time

package
v1.11.2 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2024 License: MIT Imports: 8 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"
)

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 EncodeType)

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 int64

func (Date) GormDataType

func (ts Date) GormDataType() string

func (Date) MarshalJSON

func (d Date) MarshalJSON() ([]byte, error)

func (*Date) Scan

func (d *Date) Scan(value interface{}) (err error)

Scan scan time.

func (Date) Time added in v1.5.11

func (d Date) Time() time.Time

func (*Date) UnmarshalJSON

func (d *Date) UnmarshalJSON(data []byte) error

func (Date) Value

func (d Date) Value() (driver.Value, error)

Value get time value.

type DateStr added in v1.5.11

type DateStr = StrTime[Edate]

func NewDateStr added in v1.5.11

func NewDateStr(t time.Time) DateStr

type DateTime added in v1.5.11

type DateTime int64

func (DateTime) GormDataType added in v1.5.11

func (ts DateTime) GormDataType() string

func (DateTime) MarshalJSON added in v1.5.11

func (d DateTime) MarshalJSON() ([]byte, error)

func (*DateTime) Scan added in v1.5.11

func (d *DateTime) Scan(value interface{}) (err error)

Scan scan time.

func (DateTime) Time added in v1.5.11

func (d DateTime) Time() time.Time

func (*DateTime) UnmarshalJSON added in v1.5.11

func (d *DateTime) UnmarshalJSON(data []byte) error

func (DateTime) Value added in v1.5.11

func (d DateTime) Value() (driver.Value, error)

Value get time value.

type DateTimeStr added in v1.5.11

type DateTimeStr = StrTime[EdateTime]

time.DateTime

func NewDateTimeStr added in v1.5.11

func NewDateTimeStr(t time.Time) DateTimeStr

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 Edate added in v1.5.11

type Edate struct{}

func (Edate) Encoding added in v1.5.11

func (Edate) Encoding() *Encoding

func (Edate) Layout added in v1.5.11

func (Edate) Layout() string

type EdateTime added in v1.5.11

type EdateTime struct{}

func (EdateTime) Encoding added in v1.5.11

func (EdateTime) Encoding() *Encoding

func (EdateTime) Layout added in v1.5.11

func (EdateTime) Layout() string

type Encode added in v1.5.11

type Encode interface {
	Encoding() *Encoding
}

type EncodeType added in v1.5.11

type EncodeType int8
const (
	EncodeTypeLayout EncodeType = iota
	EncodeTypeUnixSeconds
	EncodeTypeUnixMilliseconds
	EncodeTypeUnixMicroseconds
	EncodeTypeUnixNanoseconds
)

type Encoding added in v1.5.11

type Encoding struct {
	EncodeType
	Layout string
}

func (*Encoding) SetJsonType added in v1.7.3

func (u *Encoding) SetJsonType(typ EncodeType)

func (*Encoding) SetLayout added in v1.5.11

func (u *Encoding) SetLayout(l string)

type Etime added in v1.5.11

type Etime struct{}

func (Etime) Encoding added in v1.5.11

func (Etime) Encoding() *Encoding

func (Etime) Layout added in v1.5.11

func (Etime) Layout() string

type FixTicker added in v1.5.11

type FixTicker time.Ticker

func (*FixTicker) Reset added in v1.5.11

func (t *FixTicker) Reset(d time.Duration) bool

func (*FixTicker) Stop added in v1.5.11

func (t *FixTicker) Stop() bool

func (*FixTicker) Wait added in v1.5.11

func (t *FixTicker) Wait()

type Layout added in v1.5.11

type Layout interface {
	Layout() string
}

type MicroTime added in v1.5.11

type MicroTime struct{}

func (MicroTime) Encoding added in v1.7.3

func (MicroTime) Encoding() *Encoding

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) Encoding added in v1.7.3

func (MilliTime) Encoding() *Encoding

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) Encoding added in v1.7.3

func (NanoTime) Encoding() *Encoding

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 RandTicker added in v1.5.11

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

func NewRandTicker added in v1.5.11

func NewRandTicker(minInterval, maxInterval time.Duration) *RandTicker

minInterval:最小等待时间 maxInterval:最大等待时间 maxInterval-minInterval: 等待范围

func (*RandTicker) Reset added in v1.5.11

func (t *RandTicker) Reset(d time.Duration) bool

设置最小间隔

func (*RandTicker) Stop added in v1.5.11

func (t *RandTicker) Stop() bool

func (*RandTicker) Wait added in v1.5.11

func (t *RandTicker) Wait()

type SecondTime added in v1.5.11

type SecondTime struct{}

func (SecondTime) Encoding added in v1.7.3

func (SecondTime) Encoding() *Encoding

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 Ticker added in v1.5.11

type Ticker interface {
	Reset(time.Duration) bool
	Stop() bool
	Wait()
}

func NewTicker added in v1.5.11

func NewTicker(interval time.Duration) Ticker

type Time

type Time[T Encode] time.Time

func NewTime added in v1.5.11

func NewTime[T Encode](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]) Time added in v1.5.11

func (dt Time[T]) Time() time.Time

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 = Time[MicroTime]

type UnixMilliTime added in v1.6.15

type UnixMilliTime = Time[MilliTime]

type UnixNanoTime

type UnixNanoTime = Time[NanoTime]

type UnixSecondTime added in v1.6.17

type UnixSecondTime = Time[SecondTime]

Jump to

Keyboard shortcuts

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