Documentation ¶
Overview ¶
Package time provides some useful functions about time.
Index ¶
- Constants
- func DateTimeToTs(dt string) int64
- func GetBeijingTime(layout, value string) (t time.Time, err error)
- func GetDayBeginMoment(t time.Time) time.Time
- func GetDayBeginMomentTs(ts int64) time.Time
- func GetDayElapsedMs(t time.Time) int64
- func GetDayElapsedNs(t time.Time) int64
- func GetDayElapsedS(t time.Time) int64
- func GetDayElapsedUs(t time.Time) int64
- func GetDayEndMoment(t time.Time) time.Time
- func GetDayEndMomentTs(uts int64) time.Time
- func GetDaysBtwTs(ts0, ts1 int64) int64
- func GetFriDate(t time.Time) string
- func GetHoursBtwTs(ts0, ts1 int64) int64
- func GetMinutesBtwTs(ts0, ts1 int64) int64
- func GetMonDate(t time.Time) string
- func GetNowDate() string
- func GetNowDateTime() string
- func GetNowDateTimeZ() string
- func GetNowMs() int64
- func GetNowNs() int64
- func GetNowS() int64
- func GetNowTime() string
- func GetNowUs() int64
- func GetSatDate(t time.Time) string
- func GetSunDate(t time.Time) string
- func GetThursDate(t time.Time) string
- func GetTuesDate(t time.Time) string
- func GetWedDate(t time.Time) string
- func GetWeekday(t time.Time, w time.Weekday) time.Time
- func IsLeapYear(year int) bool
- func IsSameDay(ts1, ts2 int64) bool
- func IsSameHour(ts1, ts2 int64) bool
- func IsSameMinute(ts1, ts2 int64) bool
- func IsSameMonth(ts1, ts2 int64) bool
- func IsSameWeek(ts1, ts2 int64) bool
- func IsSameYear(ts1, ts2 int64) bool
- func TimeCost() func() time.Duration
- func TsToDateTime(ts int64) string
- type TimeCounter
Constants ¶
const ( YFormatNum = "2006" YMFormatNum = "200601" DateFormatNum = "20060102" DateHFormatNum = "2006010215" DateHMFormatNum = "200601021504" DateTimeFormatNum = "20060102150405" HFormatNum = "15" HMFormatNum = "1504" TimeFormatNum = "150405" // Deprecated: please use standard library time.DateOnly DateFormat = "2006-01-02" // Deprecated: please use standard library time.TimeOnly TimeFormat = "15:04:05" // Deprecated: please use standard library time.DateTime DateTimeFormat = "2006-01-02 15:04:05" DateTimeFormatMilli = "2006-01-02 15:04:05.000" DateTimeFormatMicro = "2006-01-02 15:04:05.000000" DateTimeFormatNano = "2006-01-02 15:04:05.000000000" )
Variables ¶
This section is empty.
Functions ¶
func DateTimeToTs ¶
DateTimeToTs converts datetime in YYYY-MM-DD hh:mm:ss to unix timestamp.
func GetBeijingTime ¶ added in v0.0.52
GetBeijingTime gets Beijing Time from time layout and value string. The location name Asia/Shanghai from IANA Time Zone Database standards for Beijing Time.
func GetDayBeginMoment ¶
GetDayBeginMoment gets the starting moment of one day.
func GetDayBeginMomentTs ¶
GetDayBeginMomentTs gets the starting moment of one day specified by UNIX timestamp.
func GetDayElapsedMs ¶
GetDayElapsedMs gets the elapsed milliseconds since the starting moment of one day.
func GetDayElapsedNs ¶
GetDayElapsedNs gets the elapsed nanoseconds since the starting moment of one day.
func GetDayElapsedS ¶
GetDayElapsedS gets the elapsed seconds since the starting moment of one day.
func GetDayElapsedUs ¶
GetDayElapsedUs gets the elapsed microseconds since the starting moment of one day.
func GetDayEndMoment ¶
GetDayEndMoment gets the ending moment of one day.
func GetDayEndMomentTs ¶
GetDayEndMomentTs gets the ending moment of one day specified by UNIX timestamp.
func GetDaysBtwTs ¶
GetDaysBtwTs gets the number of days between two timestamps and round down.
func GetFriDate ¶
GetFriDate gets friday date in format 2006-01-02.
func GetHoursBtwTs ¶
GetHoursBtwTs gets the number of hours between two timestamps and round down.
func GetMinutesBtwTs ¶
GetMinutesBtwTs gets the number of hours between two timestamps and round down.
func GetMonDate ¶
GetMonDate gets monday date in format 2006-01-02.
func GetNowDateTime ¶
func GetNowDateTime() string
GetNowDateTime gets now datetime in YYYY-MM-DD hh:mm:ss.
func GetNowDateTimeZ ¶
func GetNowDateTimeZ() string
GetNowDateTimeZ gets now datetime with zone in YYYY-MM-DD hh:mm:ss Zone e.g. 2020-05-11 23:18:07 +08:00.
func GetSatDate ¶
GetSatDate gets saturday date in format 2006-01-02.
func GetSunDate ¶
GetSunDate gets sunday date in format 2006-01-02.
func GetThursDate ¶
GetThursDate gets thursday date in format 2006-01-02.
func GetTuesDate ¶
GetTuesDate gets tuesday date in format 2006-01-02.
func GetWedDate ¶
GetWedDate gets wednesday date in format 2006-01-02.
func GetWeekday ¶
GetWeekday gets the weekday time.
func IsSameHour ¶
IsSameHour checks the unix timestamp whether is the same hour.
func IsSameMinute ¶
IsSameMinute checks the unix timestamp whether is the same minute.
func IsSameMonth ¶
IsSameMonth checks the unix timestamp whether is the same month.
func IsSameWeek ¶
IsSameWeek checks the unix timestamp whether is the same week.
func IsSameYear ¶
IsSameYear checks the unix timestamp whether is the same year.
func TsToDateTime ¶
TsToDateTime converts unix timestamp to local datetime in YYYY-MM-DD hh:mm:ss.
Types ¶
type TimeCounter ¶
TimeCounter is used to count time interval.
func (*TimeCounter) GetD ¶
func (t *TimeCounter) GetD() time.Duration
GetD returns the time interval from the beginning to now in time.Duration.
func (*TimeCounter) GetMs ¶
func (t *TimeCounter) GetMs() int64
GetMs returns the time interval from the beginning to now in millisecond.
func (*TimeCounter) GetNs ¶
func (t *TimeCounter) GetNs() int64
GetNs returns the time interval from the beginning to now in nanosecond.
func (*TimeCounter) GetS ¶
func (t *TimeCounter) GetS() int64
GetS returns the time interval from the beginning to now in second.
func (*TimeCounter) GetUs ¶
func (t *TimeCounter) GetUs() int64
GetUs returns the time interval from the beginning to now in microsecond.