time

package
v1.6.15 Latest Latest
Warning

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

Go to latest
Published: May 11, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SecondsOfDay    = 24 * 60 * 60
	SecondsOfMinute = 60
	TimeDay         = SecondsOfDay * time.Second
)
View Source
const (
	TimeFormat            = "2006-01-02 15:04:05.999999"
	TimeFormatDisplay     = "2006-01-02 15:04:05"
	TimeFormatPostgresDB  = time.RFC3339
	TimeFormatNoDate      = "15:04:05"
	DayEndTime            = "23:59:59"
	DayEndTimeWithSpace   = " 23:59:59"
	DayBeginTime          = "00:00:00"
	DayBeginTimeWithSpace = " 00:00:00"
	DateFormat            = "2006-01-02"
	TimeFormatCompact     = "20060102150405"
	TimeFormatRFC1        = "2006/01/02 - 15:04:05"
)
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 Parse

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

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

Types

type Constraints added in v1.6.15

type Constraints interface {
	DefaultTime | DateTime | UnixTime | UnixMilliTime | UnixNanoTime | DisplayTime
}

type DateTime added in v1.5.11

type DateTime struct{}

type DefaultTime added in v1.6.15

type DefaultTime struct{}

type DisplayTime added in v1.6.15

type DisplayTime struct{}

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 NanoTimeStamp added in v1.6.15

type NanoTimeStamp int64

func (NanoTimeStamp) Format added in v1.6.15

func (ts NanoTimeStamp) Format(foramt string) string

func (NanoTimeStamp) GormDataType added in v1.6.15

func (ts NanoTimeStamp) GormDataType() string

GormDataType gorm common data type

func (NanoTimeStamp) MarshalJSON added in v1.6.15

func (t NanoTimeStamp) MarshalJSON() ([]byte, error)

func (*NanoTimeStamp) Scan added in v1.6.15

func (ts *NanoTimeStamp) Scan(value interface{}) (err error)

func (NanoTimeStamp) Time added in v1.6.15

func (t NanoTimeStamp) Time() time.Time

func (*NanoTimeStamp) UnmarshalJSON added in v1.6.15

func (t *NanoTimeStamp) UnmarshalJSON(data []byte) error

func (NanoTimeStamp) Value added in v1.6.15

func (ts NanoTimeStamp) Value() (driver.Value, error)

type SecondTimeStamp added in v1.6.15

type SecondTimeStamp int64

func (SecondTimeStamp) Format added in v1.6.15

func (ts SecondTimeStamp) Format(foramt string) string

func (SecondTimeStamp) GormDataType added in v1.6.15

func (ts SecondTimeStamp) GormDataType() string

GormDataType gorm common data type

func (SecondTimeStamp) MarshalJSON added in v1.6.15

func (t SecondTimeStamp) MarshalJSON() ([]byte, error)

func (*SecondTimeStamp) Scan added in v1.6.15

func (ts *SecondTimeStamp) Scan(value interface{}) (err error)

func (SecondTimeStamp) Time added in v1.6.15

func (t SecondTimeStamp) Time() time.Time

func (*SecondTimeStamp) UnmarshalJSON added in v1.6.15

func (t *SecondTimeStamp) UnmarshalJSON(data []byte) error

func (SecondTimeStamp) Value added in v1.6.15

func (ts SecondTimeStamp) Value() (driver.Value, error)

type Time

type Time[T any] time.Time

TODO: 这是不优雅的实现

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 int64

毫秒

func NewTimeStamp added in v1.5.11

func NewTimeStamp(t time.Time) Timestamp

func (Timestamp) MarshalJSON added in v1.6.15

func (t Timestamp) MarshalJSON() ([]byte, error)

func (*Timestamp) Scan added in v1.6.15

func (t *Timestamp) Scan(value interface{}) (err error)

Scan scan time.

func (Timestamp) Time added in v1.6.15

func (t Timestamp) Time() time.Time

Time get time.

func (*Timestamp) UnmarshalJSON added in v1.6.15

func (t *Timestamp) UnmarshalJSON(data []byte) error

func (Timestamp) Value added in v1.6.15

func (t Timestamp) Value() (driver.Value, error)

Value get time value.

type Timestr added in v1.6.15

type Timestr string

time.DateTime

func NewTimeStr added in v1.6.15

func NewTimeStr(t time.Time) Timestr

func (Timestr) Time added in v1.6.15

func (t Timestr) Time() (time.Time, error)

type UnionTime

type UnionTime struct {
	time.Time
	// contains filtered or unexported fields
}

对应数据库datetime或timestamp,或date typ 0 序列化为 "2006-01-02 15:04:05",typ 1序列化为"2006-01-02",typ 2 序列化为秒时间戳, typ 3序列化为毫秒时间戳, typ 4 序列化为纳秒时间戳 序列化,反序列化前需设置typ

func NewUnionTime

func NewUnionTime(t time.Time, typ uint8) UnionTime

func ZeroUnionTime

func ZeroUnionTime(typ uint8) UnionTime

func (UnionTime) MarshalJSON

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

func (*UnionTime) Scan

func (ut *UnionTime) Scan(value interface{}) (err error)

func (*UnionTime) Type

func (ut *UnionTime) Type(typ uint8) UnionTime

func (*UnionTime) UnmarshalJSON

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

func (UnionTime) Value

func (ut UnionTime) Value() (driver.Value, error)

type UnixMicroTime added in v1.6.15

type UnixMicroTime struct{}

type UnixMilliTime added in v1.6.15

type UnixMilliTime struct{}

type UnixNanoTime

type UnixNanoTime struct{}

type UnixTime

type UnixTime struct{}

Jump to

Keyboard shortcuts

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