time

package
v1.7.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SecondsOfDay    = 24 * 60 * 60
	SecondsOfMinute = 60
	TimeDay         = SecondsOfDay * time.Second
)
View Source
const (
	LayoutTimeMacro   = "2006-01-02 15:04:05.999999"
	LayoutDateTime    = "2006-01-02 15:04:05"
	LayoutRFC3339     = time.RFC3339
	LayoutTime        = "15:04:05"
	LayoutDate        = "2006-01-02"
	LayoutCompactTime = "20060102150405"
	LayoutRFC1        = "2006/01/02 - 15:04:05"
)
View Source
const (
	DayEndTime            = "23:59:59"
	DayEndTimeWithSpace   = " 23:59:59"
	DayBeginTime          = "00:00:00"
	DayBeginTimeWithSpace = " 00:00:00"
)
View Source
const (
	Day        = time.Hour * 24
	MonthDay30 = Day * 30
	MonthDay31 = Day * 31
	MonthDay28 = Day * 28
	MonthDay29 = Day * 29
	Month      = MonthDay30
	YearDay365 = Day * 365
	YearDay366 = Day * 366
	Year       = YearDay365
)
View Source
const (
	January   = "January"
	February  = "February"
	March     = "March"
	April     = "April"
	May       = "May"
	June      = "June"
	July      = "July"
	August    = "August"
	September = "September"
	October   = "October"
	November  = "November"
	December  = "December"
)
View Source
const (
	Monday    = "Monday"
	Tuesday   = "Tuesday"
	Wednesday = "Wednesday"
	Thursday  = "Thursday"
	Friday    = "Friday"
	Saturday  = "Saturday"
	Sunday    = "Sunday"
)
View Source
const (
	JsonTypeLayout jsonType = iota
	JsonTypeUnixSeconds
	JsonTypeUnixMilliseconds
	JsonTypeUnixMicroseconds
	JsonTypeUnixNanoseconds
)

Variables

View Source
var ZeroTime = time.Time{}

Functions

func Format

func Format(t time.Time) string

func FormatRelativeTime added in v1.5.11

func FormatRelativeTime(fromTime time.Time) string

func GetTodayZeroTime

func GetTodayZeroTime() time.Time

GetTodayZeroTime 返回今天零点的time

func GetTomorrowYMD

func GetTomorrowYMD(sep string) string

GetTomorrowYMD 得到以sep为分隔符的年、月、日字符串(明天)

func GetYM

func GetYM(time time.Time, sep string) string

GetYM 得到以sep为分隔符的年、月字符串(今天所属于的月份)

func GetYMD

func GetYMD(time time.Time, sep string) string

GetTodayYMD 得到以sep为分隔符的年、月、日字符串(今天)

func GetYesterdayYMD

func GetYesterdayYMD(sep string) string

GetYesterdayYMD 得到以sep为分隔符的年、月、日字符串(昨天)

func GetYesterdayZeroTime

func GetYesterdayZeroTime() time.Time

GetYesterdayZeroTime 返回昨天零点的time

func MarshalJSON added in v1.5.11

func MarshalJSON(t time.Time) ([]byte, error)

func MarshalText added in v1.5.11

func MarshalText(t time.Time) ([]byte, error)

func Parse

func Parse(layout, value string) (time.Time, error)

func SetJsonType added in v1.7.2

func SetJsonType(typ jsonType)

func SetLayout added in v1.7.2

func SetLayout(l string)

func SetUnixSysTime

func SetUnixSysTime(t time.Time)

设置系统时间

func StdDuration

func StdDuration(td time.Duration, stdTd time.Duration) time.Duration

标准化TimeDuration

func StrToIntMonth

func StrToIntMonth(month string) int

StrToIntMonth 字符串月份转整数月份

func SyncHwTime

func SyncHwTime()

func TimeCost

func TimeCost(start time.Time) time.Duration

func TodayZeroTime

func TodayZeroTime() time.Time

func UnixNano added in v1.5.11

func UnixNano(nsec int64) time.Time

func UnmarshalJSON added in v1.5.11

func UnmarshalJSON(t *time.Time, data []byte) error

func UnmarshalText added in v1.5.11

func UnmarshalText(t *time.Time, data []byte) error

Types

type Date

type Date = Time[date]

type DateStr added in v1.5.11

type DateStr = StrTime[date]

func NewDateStr added in v1.5.11

func NewDateStr(t time.Time) DateStr

type DateTime added in v1.5.11

type DateTime = Time[dateTime]

type DateTimeStr added in v1.5.11

type DateTimeStr = StrTime[dateTime]

time.DateTime

func NewDateTimeStr added in v1.5.11

func NewDateTimeStr(t time.Time) DateTimeStr

type DefaultTime added in v1.6.15

type DefaultTime struct{}

func (DefaultTime) Layout added in v1.6.17

func (DefaultTime) Layout() string

type Duration

type Duration time.Duration

Duration be used toml unmarshal string time, like 1s, 500ms.

func (Duration) MarshalText added in v1.1.0

func (d Duration) MarshalText() ([]byte, error)

func (Duration) Shrink

Shrink will decrease the duration by comparing with context's timeout duration and return new timeout\context\CancelFunc.

func (*Duration) UnmarshalText

func (d *Duration) UnmarshalText(text []byte) error

UnmarshalText unmarshal text to duration.

type Encoding added in v1.5.11

type Encoding struct {
	// contains filtered or unexported fields
}

func (*Encoding) JsonType added in v1.7.2

func (u *Encoding) JsonType(typ jsonType)

func (*Encoding) Layout added in v1.5.11

func (u *Encoding) Layout(l string)

type Layout added in v1.5.11

type Layout interface {
	Layout() string
}

type MicroTime added in v1.5.11

type MicroTime struct{}

func (MicroTime) Time added in v1.6.17

func (MicroTime) Time(t int64) time.Time

func (MicroTime) Timestamp added in v1.6.17

func (MicroTime) Timestamp(t time.Time) int64

type MicroTimestamp added in v1.5.11

type MicroTimestamp = timestamp[MicroTime]

type MilliTime added in v1.5.11

type MilliTime struct{}

func (MilliTime) Time added in v1.6.17

func (MilliTime) Time(t int64) time.Time

func (MilliTime) Timestamp added in v1.6.17

func (MilliTime) Timestamp(t time.Time) int64

type MilliTimestamp added in v1.5.11

type MilliTimestamp = timestamp[MilliTime]

type NanoTime added in v1.5.11

type NanoTime struct{}

go生成的纳米级时间戳最后两位恒为0

func (NanoTime) Time added in v1.6.17

func (NanoTime) Time(t int64) time.Time

func (NanoTime) Timestamp added in v1.6.17

func (NanoTime) Timestamp(t time.Time) int64

type NanoTimestamp added in v1.5.11

type NanoTimestamp = timestamp[NanoTime]

type SecondTime added in v1.5.11

type SecondTime struct{}

func (SecondTime) Time added in v1.6.17

func (SecondTime) Time(t int64) time.Time

func (SecondTime) Timestamp added in v1.6.17

func (SecondTime) Timestamp(t time.Time) int64

type SecondTimestamp added in v1.5.11

type SecondTimestamp = timestamp[SecondTime]

type StrTime added in v1.7.2

type StrTime[T Layout] string

func (StrTime[T]) MarshalJSON added in v1.7.2

func (dt StrTime[T]) MarshalJSON() ([]byte, error)

func (StrTime[T]) Time added in v1.7.2

func (t StrTime[T]) Time() (time.Time, error)

func (*StrTime[T]) UnmarshalJSON added in v1.7.2

func (dt *StrTime[T]) UnmarshalJSON(data []byte) error

type Time

type Time[T Layout] time.Time

func NewTime added in v1.5.11

func NewTime[T Layout](t time.Time) Time[T]

func (Time[T]) Format

func (dt Time[T]) Format(format string) string

func (*Time[T]) GobDecode

func (dt *Time[T]) GobDecode(data []byte) error

func (Time[T]) GobEncode

func (dt Time[T]) GobEncode() ([]byte, error)

func (Time[T]) GormDataType

func (dt Time[T]) GormDataType() string

func (Time[T]) MarshalBinary

func (dt Time[T]) MarshalBinary() ([]byte, error)

func (Time[T]) MarshalJSON

func (dt Time[T]) MarshalJSON() ([]byte, error)

func (*Time[T]) Scan

func (dt *Time[T]) Scan(value interface{}) (err error)

func (*Time[T]) UnmarshalBinary

func (dt *Time[T]) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.

func (*Time[T]) UnmarshalJSON

func (dt *Time[T]) UnmarshalJSON(data []byte) error

func (Time[T]) Value

func (dt Time[T]) Value() (driver.Value, error)

type Timestamp added in v1.5.11

type Timestamp = timestamp[MilliTime]

毫秒

func NewTimeStamp added in v1.5.11

func NewTimeStamp(t time.Time) Timestamp

type TimestampConstraints added in v1.5.11

type TimestampConstraints interface {
	Timestamp(time.Time) int64
	Time(int64) time.Time
}

type UnionTime

type UnionTime struct {
	time.Time
	Encoding
}

func (UnionTime) MarshalJSON

func (u UnionTime) MarshalJSON() ([]byte, error)

func (*UnionTime) UnmarshalJSON

func (u *UnionTime) UnmarshalJSON(data []byte) error

type UnixMicroTime added in v1.6.15

type UnixMicroTime = UnixTime[MicroTime]

type UnixMilliTime added in v1.6.15

type UnixMilliTime = UnixTime[MilliTime]

type UnixNanoTime

type UnixNanoTime = UnixTime[NanoTime]

type UnixSecondTime added in v1.6.17

type UnixSecondTime = UnixTime[SecondTime]

type UnixTime

type UnixTime[T TimestampConstraints] time.Time

func NewUnixTime added in v1.6.17

func NewUnixTime[T TimestampConstraints](t time.Time) UnixTime[T]

func (UnixTime[T]) Format

func (dt UnixTime[T]) Format(format string) string

func (*UnixTime[T]) GobDecode

func (dt *UnixTime[T]) GobDecode(data []byte) error

func (UnixTime[T]) GobEncode

func (dt UnixTime[T]) GobEncode() ([]byte, error)

func (UnixTime[T]) GormDataType

func (dt UnixTime[T]) GormDataType() string

func (UnixTime[T]) MarshalBinary

func (dt UnixTime[T]) MarshalBinary() ([]byte, error)

func (UnixTime[T]) MarshalJSON

func (dt UnixTime[T]) MarshalJSON() ([]byte, error)

func (*UnixTime[T]) Scan

func (dt *UnixTime[T]) Scan(value interface{}) (err error)

func (*UnixTime[T]) UnmarshalBinary

func (dt *UnixTime[T]) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.

func (*UnixTime[T]) UnmarshalJSON

func (dt *UnixTime[T]) UnmarshalJSON(data []byte) error

func (UnixTime[T]) Value

func (dt UnixTime[T]) Value() (driver.Value, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL