time

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2023 License: MulanPSL-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package time provides some useful functions about time.

Index

Constants

View Source
const (
	YFormatNum          = "2006"
	YMFormatNum         = "200601"
	DateFormatNum       = "20060102"
	DateHFormatNum      = "2006010215"
	DateHMFormatNum     = "200601021504"
	DateTimeFormatNum   = "20060102150405"
	HFormatNum          = "15"
	HMFormatNum         = "1504"
	TimeFormatNum       = "150405"
	DateFormat          = "2006-01-02"
	TimeFormat          = "15:04:05"
	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

func DateTimeToTs(dt string) int64

DateTimeToTs converts datetime in YYYY-MM-DD hh:mm:ss to unix timestamp.

func GetBeijingTime

func GetBeijingTime(layout, value string) (t time.Time, err error)

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

func GetDayBeginMoment(t time.Time) time.Time

GetDayBeginMoment gets the starting moment of one day.

func GetDayBeginMomentTs

func GetDayBeginMomentTs(ts int64) time.Time

GetDayBeginMomentTs gets the starting moment of one day specified by UNIX timestamp.

func GetDayElapsedMs

func GetDayElapsedMs(t time.Time) int64

GetDayElapsedMs gets the elapsed milliseconds since the starting moment of one day.

func GetDayElapsedNs

func GetDayElapsedNs(t time.Time) int64

GetDayElapsedNs gets the elapsed nanoseconds since the starting moment of one day.

func GetDayElapsedS

func GetDayElapsedS(t time.Time) int64

GetDayElapsedS gets the elapsed seconds since the starting moment of one day.

func GetDayElapsedUs

func GetDayElapsedUs(t time.Time) int64

GetDayElapsedUs gets the elapsed microseconds since the starting moment of one day.

func GetDayEndMoment

func GetDayEndMoment(t time.Time) time.Time

GetDayEndMoment gets the ending moment of one day.

func GetDayEndMomentTs

func GetDayEndMomentTs(uts int64) time.Time

GetDayEndMomentTs gets the ending moment of one day specified by UNIX timestamp.

func GetDaysBtwTs

func GetDaysBtwTs(ts0, ts1 int64) int64

GetDaysBtwTs gets the number of days between two timestamps and round down.

func GetFriDate

func GetFriDate(t time.Time) string

GetFriDate gets friday date in format 2006-01-02.

func GetHoursBtwTs

func GetHoursBtwTs(ts0, ts1 int64) int64

GetHoursBtwTs gets the number of hours between two timestamps and round down.

func GetMinutesBtwTs

func GetMinutesBtwTs(ts0, ts1 int64) int64

GetMinutesBtwTs gets the number of hours between two timestamps and round down.

func GetMonDate

func GetMonDate(t time.Time) string

GetMonDate gets monday date in format 2006-01-02.

func GetNowDate

func GetNowDate() string

GetNowDate gets now date in YYYY-MM-DD.

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 GetNowMs

func GetNowMs() int64

GetNowMs gets unix timestamp in millisecond.

func GetNowNs

func GetNowNs() int64

GetNowNs gets unix timestamp in nanosecond.

func GetNowS

func GetNowS() int64

GetNowS gets unix timestamp in second.

func GetNowTime

func GetNowTime() string

GetNowDate gets now time in hh:mm:ss.

func GetNowUs

func GetNowUs() int64

GetNowUs gets unix timestamp in microsecond.

func GetSatDate

func GetSatDate(t time.Time) string

GetSatDate gets saturday date in format 2006-01-02.

func GetSunDate

func GetSunDate(t time.Time) string

GetSunDate gets sunday date in format 2006-01-02.

func GetThursDate

func GetThursDate(t time.Time) string

GetThursDate gets thursday date in format 2006-01-02.

func GetTuesDate

func GetTuesDate(t time.Time) string

GetTuesDate gets tuesday date in format 2006-01-02.

func GetWedDate

func GetWedDate(t time.Time) string

GetWedDate gets wednesday date in format 2006-01-02.

func GetWeekday

func GetWeekday(t time.Time, w time.Weekday) time.Time

GetWeekday gets the weekday time.

func IsLeapYear

func IsLeapYear(year int) bool

IsLeapYear checks the year whether is leap year.

func IsSameDay

func IsSameDay(ts1, ts2 int64) bool

IsSameDay checks the unix timestamp whether is the same day.

func IsSameHour

func IsSameHour(ts1, ts2 int64) bool

IsSameHour checks the unix timestamp whether is the same hour.

func IsSameMinute

func IsSameMinute(ts1, ts2 int64) bool

IsSameMinute checks the unix timestamp whether is the same minute.

func IsSameMonth

func IsSameMonth(ts1, ts2 int64) bool

IsSameMonth checks the unix timestamp whether is the same month.

func IsSameWeek

func IsSameWeek(ts1, ts2 int64) bool

IsSameWeek checks the unix timestamp whether is the same week.

func IsSameYear

func IsSameYear(ts1, ts2 int64) bool

IsSameYear checks the unix timestamp whether is the same year.

func TimeCost

func TimeCost() func() time.Duration

TimeCost counts time cost.

func TsToDateTime

func TsToDateTime(ts int64) string

TsToDateTime converts unix timestamp to local datetime in YYYY-MM-DD hh:mm:ss.

Types

type TimeCounter

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

TimeCounter is used to count time interval.

func NewTimeCounter

func NewTimeCounter() (t *TimeCounter)

NewTimeCounter creates a time counter.

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.

func (*TimeCounter) Reset

func (t *TimeCounter) Reset()

Reset sets start time to now.

Jump to

Keyboard shortcuts

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