Documentation
¶
Index ¶
- Constants
- func AddDays(t time.Time, days int) time.Time
- func AddHours(t time.Time, hours int) time.Time
- func AddMinutes(t time.Time, minutes int) time.Time
- func AddMonths(t time.Time, months int) time.Time
- func AddSeconds(t time.Time, seconds int) time.Time
- func AddYears(t time.Time, years int) time.Time
- func ConvertTimeZone(t time.Time, fromZone, toZone string) (time.Time, error)
- func DaysBetween(t1, t2 time.Time) int
- func DaysInCurrentMonth() int
- func DaysInMonth(year int, month time.Month) int
- func EndOfDay(t time.Time) time.Time
- func EndOfMonth(t time.Time) time.Time
- func EndOfQuarter(t time.Time) time.Time
- func EndOfWeek(t time.Time) time.Time
- func EndOfYear(t time.Time) time.Time
- func FormatDelay(ts time.Time) string
- func FormatDuration(d time.Duration) string
- func FormatNow(layout string) string
- func FormatTimeLocal(t time.Time, layout string) string
- func FormatTimeUTC(t time.Time, layout string) string
- func FormatTimeWithLayout(t time.Time, layout string) string
- func FormatUnix(unixTime interface{}, format string) string
- func GetAge(birthdate, reference time.Time) int
- func GetCurrentAge(birthdate time.Time) int
- func GetCurrentDate() string
- func GetCurrentDateTime() string
- func GetCurrentDayOfYear() int
- func GetCurrentQuarter() int
- func GetCurrentTime() string
- func GetCurrentTimeZone() string
- func GetCurrentTimeZoneOffset() int
- func GetCurrentUTCOffset() float64
- func GetCurrentUTCOffsetString() string
- func GetCurrentWeekOfYear() int
- func GetCurrentWeekday() time.Weekday
- func GetCurrentWeekdayCn() string
- func GetDayOfYear(t time.Time) int
- func GetDaysInCurrentYear() int
- func GetDaysInYear(year int) int
- func GetElapsedDaysInCurrentYear() int
- func GetElapsedDaysInYear(t time.Time) int
- func GetElapsedPercentageOfCurrentYear() float64
- func GetElapsedPercentageOfYear(t time.Time) float64
- func GetNextWeekday(t time.Time, weekday time.Weekday) time.Time
- func GetPreviousWeekday(t time.Time, weekday time.Weekday) time.Time
- func GetQuarter(t time.Time) int
- func GetRemainingDaysInCurrentYear() int
- func GetRemainingDaysInYear(t time.Time) int
- func GetRemainingPercentageOfCurrentYear() float64
- func GetRemainingPercentageOfYear(t time.Time) float64
- func GetTimeInLocation(t time.Time, location *time.Location) time.Time
- func GetTimeInLocationName(t time.Time, locationName string) (time.Time, error)
- func GetTimeZone(t time.Time) string
- func GetTimeZoneOffset(t time.Time) int
- func GetUTCOffset(t time.Time) float64
- func GetUTCOffsetString(t time.Time) string
- func GetUTCTime() time.Time
- func GetWeekOfYear(t time.Time) int
- func GetWeekday(t time.Time) time.Weekday
- func GetWeekdayCn(t time.Time) string
- func GetWeekdayName(t time.Time) string
- func IsAfter(t1, t2 time.Time) bool
- func IsBefore(t1, t2 time.Time) bool
- func IsBetween(t, start, end time.Time) bool
- func IsCurrentLeapYear() bool
- func IsEqual(t1, t2 time.Time) bool
- func IsLeapYear(year int) bool
- func IsLocal(t time.Time) bool
- func IsSameDay(t1, t2 time.Time) bool
- func IsSameMonth(t1, t2 time.Time) bool
- func IsSameYear(t1, t2 time.Time) bool
- func IsUTC(t time.Time) bool
- func IsValidDate(year, month, day int) bool
- func IsValidDateTime(year, month, day, hour, minute, second int) bool
- func IsValidTime(hour, minute, second int) bool
- func IsWeekday(t time.Time) bool
- func IsWeekend(t time.Time) bool
- func MonthsBetween(t1, t2 time.Time) int
- func MustParseLong(s string) time.Time
- func MustParseShort(s string) time.Time
- func ParseDateCompact(s string) (time.Time, error)
- func ParseDatetimeCompact(s string) (time.Time, error)
- func ParseISO8601(s string) (time.Time, error)
- func ParseLong(s string) (time.Time, error)
- func ParseShort(s string) (time.Time, error)
- func ParseUTC(utc string, format string) (local time.Time, err error)
- func ParseUnix(timestamp int64) time.Time
- func ParseUnixMilli(timestamp int64) time.Time
- func ParseWithLayout(layout, value string) (time.Time, error)
- func SleepDuration(d time.Duration)
- func SleepHour()
- func SleepMicrosecond(sleep int)
- func SleepMillisecond(sleep int)
- func SleepMinute()
- func SleepRandMilli(max int)
- func SleepRandMilliWithSeed(max int, seed int64)
- func SleepRandSecond(max int)
- func SleepRandSecondWithSeed(max int, seed int64)
- func SleepSecond(sleep int)
- func SleepUntil(t time.Time)
- func StartOfDay(t time.Time) time.Time
- func StartOfMonth(t time.Time) time.Time
- func StartOfQuarter(t time.Time) time.Time
- func StartOfWeek(t time.Time) time.Time
- func StartOfYear(t time.Time) time.Time
- func SubtractDays(t time.Time, days int) time.Time
- func SubtractHours(t time.Time, hours int) time.Time
- func SubtractMinutes(t time.Time, minutes int) time.Time
- func SubtractMonths(t time.Time, months int) time.Time
- func SubtractSeconds(t time.Time, seconds int) time.Time
- func SubtractYears(t time.Time, years int) time.Time
- func ToLocal(t time.Time) time.Time
- func ToUTC(t time.Time) time.Time
- func WeekdayEn2Cn(s string) string
- func WeekdayToCn(w time.Weekday) string
- func YearsBetween(t1, t2 time.Time) int
Constants ¶
const ( FormatDatetime = "2006-01-02 15:04:05" FormatParseDatetimeDash = "2006-1-2 15:4:5" FormatParseDatetimeSlash = "2006/1/2 15:4:5" FormatDay = "2006-01-02" FormatParseDayDash = "2006-1-2" FormatParseDaySlash = "2006/1/2" FormatDatetimeCompact = "20060102150405" FormatDateCompact = "20060102" FormatTime = "15:04:05" FormatParseTime = "15:4:5" FormatUTC = "2006-01-02T15:04:05Z" FormatUTC1 = "2006-01-02T15:04:05" FormatUTC2 = "2006-01-02T15:04Z" FormatISO8601 = "2006-01-02T15:04:05.999-07:00" )
const ( // Time zone names TimeZoneUTC = "UTC" // Coordinated Universal Time TimeZoneGMT = "GMT" // Greenwich Mean Time TimeZoneEST = "America/New_York" // Eastern Standard Time (North America) TimeZoneEDT = "America/New_York" // Eastern Daylight Time (North America) TimeZoneCST = "America/Chicago" // Central Standard Time (North America) TimeZoneCDT = "America/Chicago" // Central Daylight Time (North America) TimeZoneMST = "America/Denver" // Mountain Standard Time (North America) TimeZoneMDT = "America/Denver" // Mountain Daylight Time (North America) TimeZonePST = "America/Los_Angeles" // Pacific Standard Time (North America) TimeZonePDT = "America/Los_Angeles" // Pacific Daylight Time (North America) TimeZoneAKST = "America/Anchorage" // Alaska Standard Time TimeZoneAKDT = "America/Anchorage" // Alaska Daylight Time TimeZoneHST = "Pacific/Honolulu" // Hawaii Standard Time TimeZoneCET = "Europe/Paris" // Central European Time TimeZoneCEST = "Europe/Paris" // Central European Summer Time TimeZoneWET = "Europe/Lisbon" // Western European Time TimeZoneWEST = "Europe/Lisbon" // Western European Summer Time TimeZoneEET = "Europe/Helsinki" // Eastern European Time TimeZoneEEST = "Europe/Helsinki" // Eastern European Summer Time TimeZoneJST = "Asia/Tokyo" // Japan Standard Time TimeZoneCST_China = "Asia/Shanghai" // China Standard Time TimeZoneAEST = "Australia/Sydney" // Australian Eastern Standard Time TimeZoneAEDT = "Australia/Sydney" // Australian Eastern Daylight Time TimeZoneNZST = "Pacific/Auckland" // New Zealand Standard Time TimeZoneNZDT = "Pacific/Auckland" // New Zealand Daylight Time // Time zone offsets in hours TimeZoneOffsetUTC = 0 // UTC+0 TimeZoneOffsetGMT = 0 // UTC+0 TimeZoneOffsetEST = -5 // UTC-5 TimeZoneOffsetEDT = -4 // UTC-4 TimeZoneOffsetCST = -6 // UTC-6 TimeZoneOffsetCDT = -5 // UTC-5 TimeZoneOffsetMST = -7 // UTC-7 TimeZoneOffsetMDT = -6 // UTC-6 TimeZoneOffsetPST = -8 // UTC-8 TimeZoneOffsetPDT = -7 // UTC-7 TimeZoneOffsetAKST = -9 // UTC-9 TimeZoneOffsetAKDT = -8 // UTC-8 TimeZoneOffsetHST = -10 // UTC-10 TimeZoneOffsetCET = 1 // UTC+1 TimeZoneOffsetCEST = 2 // UTC+2 TimeZoneOffsetWET = 0 // UTC+0 TimeZoneOffsetWEST = 1 // UTC+1 TimeZoneOffsetEET = 2 // UTC+2 TimeZoneOffsetEEST = 3 // UTC+3 TimeZoneOffsetJST = 9 // UTC+9 TimeZoneOffsetCST_China = 8 // UTC+8 TimeZoneOffsetAEST = 10 // UTC+10 TimeZoneOffsetAEDT = 11 // UTC+11 TimeZoneOffsetNZST = 12 // UTC+12 TimeZoneOffsetNZDT = 13 // UTC+13 )
Time zone names and their UTC offsets in hours
Variables ¶
This section is empty.
Functions ¶
func AddDays ¶
AddDays adds the specified number of days to the given time.
func AddHours ¶
AddHours adds the specified number of hours to the given time.
func AddMinutes ¶
AddMinutes adds the specified number of minutes to the given time.
func AddMonths ¶
AddMonths adds the specified number of months to the given time.
func AddSeconds ¶
AddSeconds adds the specified number of seconds to the given time.
func AddYears ¶
AddYears adds the specified number of years to the given time.
func ConvertTimeZone ¶
ConvertTimeZone converts a time from one time zone to another. The fromZone and toZone parameters should be valid time zone names like "UTC", "America/New_York", etc.
func DaysBetween ¶
DaysBetween calculates the number of days between two times.
func DaysInCurrentMonth ¶
func DaysInCurrentMonth() int
DaysInCurrentMonth returns the number of days in the current month.
func DaysInMonth ¶
DaysInMonth returns the number of days in the given month and year.
func EndOfDay ¶
EndOfDay returns the end of the day (23:59:59.999999999) for the given time.
func EndOfMonth ¶
EndOfMonth returns the end of the month (last day 23:59:59.999999999) for the given time.
func EndOfQuarter ¶
EndOfQuarter returns the end of the quarter for the given time.
func EndOfWeek ¶
EndOfWeek returns the end of the week (Sunday 23:59:59.999999999) for the given time.
func EndOfYear ¶
EndOfYear returns the end of the year (December 31st 23:59:59.999999999) for the given time.
func FormatDelay ¶
FormatDelay returns a string representation of the time elapsed since the given timestamp.
func FormatDuration ¶
FormatDuration formats a duration to a human-readable string.
func FormatNow ¶
FormatNow formats the current time according to the specified layout.
func FormatTimeLocal ¶
FormatTimeLocal formats the given time in the local time zone according to the specified layout.
func FormatTimeUTC ¶
FormatTimeUTC formats the given time in UTC according to the specified layout.
func FormatTimeWithLayout ¶
FormatTimeWithLayout formats the given time.Time according to the specified layout.
func FormatUnix ¶
FormatUnix converts a Unix timestamp to a formatted time string. It supports various input types including string, int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64.
func GetAge ¶
GetAge calculates the age in years based on the birthdate and the reference date.
func GetCurrentAge ¶
GetCurrentAge calculates the current age in years based on the birthdate.
func GetCurrentDate ¶
func GetCurrentDate() string
GetCurrentDate returns the current date in the format "2006-01-02".
func GetCurrentDateTime ¶
func GetCurrentDateTime() string
GetCurrentDateTime returns the current date and time in the format "2006-01-02 15:04:05".
func GetCurrentDayOfYear ¶
func GetCurrentDayOfYear() int
GetCurrentDayOfYear returns the current day of the year (1-366).
func GetCurrentQuarter ¶
func GetCurrentQuarter() int
GetCurrentQuarter returns the current quarter (1-4).
func GetCurrentTime ¶
func GetCurrentTime() string
GetCurrentTime returns the current time in the format "15:04:05".
func GetCurrentTimeZone ¶
func GetCurrentTimeZone() string
GetCurrentTimeZone returns the name of the current time zone.
func GetCurrentTimeZoneOffset ¶
func GetCurrentTimeZoneOffset() int
GetCurrentTimeZoneOffset returns the offset in seconds east of UTC for the current time zone.
func GetCurrentUTCOffset ¶
func GetCurrentUTCOffset() float64
GetCurrentUTCOffset returns the offset between the current time and UTC in hours.
func GetCurrentUTCOffsetString ¶
func GetCurrentUTCOffsetString() string
GetCurrentUTCOffsetString returns the offset between the current time and UTC as a string (e.g., "+08:00").
func GetCurrentWeekOfYear ¶
func GetCurrentWeekOfYear() int
GetCurrentWeekOfYear returns the current ISO 8601 week number (1-53).
func GetCurrentWeekday ¶
GetCurrentWeekday returns the current weekday.
func GetCurrentWeekdayCn ¶
func GetCurrentWeekdayCn() string
GetCurrentWeekdayCn returns the current weekday in Chinese.
func GetDayOfYear ¶
GetDayOfYear returns the day of the year (1-366) for the given time.
func GetDaysInCurrentYear ¶
func GetDaysInCurrentYear() int
GetDaysInCurrentYear returns the number of days in the current year.
func GetDaysInYear ¶
GetDaysInYear returns the number of days in the given year.
func GetElapsedDaysInCurrentYear ¶
func GetElapsedDaysInCurrentYear() int
GetElapsedDaysInCurrentYear returns the number of days elapsed in the current year.
func GetElapsedDaysInYear ¶
GetElapsedDaysInYear returns the number of days elapsed in the year for the given time.
func GetElapsedPercentageOfCurrentYear ¶
func GetElapsedPercentageOfCurrentYear() float64
GetElapsedPercentageOfCurrentYear returns the percentage of the current year that has elapsed.
func GetElapsedPercentageOfYear ¶
GetElapsedPercentageOfYear returns the percentage of the year that has elapsed for the given time.
func GetNextWeekday ¶
GetNextWeekday returns the next occurrence of the specified weekday. If the current day is the specified weekday, it returns the next week's occurrence.
func GetPreviousWeekday ¶
GetPreviousWeekday returns the previous occurrence of the specified weekday. If the current day is the specified weekday, it returns the previous week's occurrence.
func GetQuarter ¶
GetQuarter returns the quarter (1-4) for the given time.
func GetRemainingDaysInCurrentYear ¶
func GetRemainingDaysInCurrentYear() int
GetRemainingDaysInCurrentYear returns the number of days remaining in the current year.
func GetRemainingDaysInYear ¶
GetRemainingDaysInYear returns the number of days remaining in the year for the given time.
func GetRemainingPercentageOfCurrentYear ¶
func GetRemainingPercentageOfCurrentYear() float64
GetRemainingPercentageOfCurrentYear returns the percentage of the current year that remains.
func GetRemainingPercentageOfYear ¶
GetRemainingPercentageOfYear returns the percentage of the year that remains for the given time.
func GetTimeInLocation ¶
GetTimeInLocation returns the given time in the specified location.
func GetTimeInLocationName ¶
GetTimeInLocationName returns the given time in the specified location name.
func GetTimeZone ¶
GetTimeZone returns the name of the time zone for the given time.
func GetTimeZoneOffset ¶
GetTimeZoneOffset returns the offset in seconds east of UTC for the given time.
func GetUTCOffset ¶
GetUTCOffset returns the offset between the given time and UTC in hours.
func GetUTCOffsetString ¶
GetUTCOffsetString returns the offset between the given time and UTC as a string (e.g., "+08:00").
func GetWeekOfYear ¶
GetWeekOfYear returns the ISO 8601 week number (1-53) for the given time.
func GetWeekday ¶
GetWeekday returns the weekday of the given time.
func GetWeekdayCn ¶
GetWeekdayCn returns the Chinese name of the weekday for the given time.
func GetWeekdayName ¶
GetWeekdayName returns the English name of the weekday for the given time.
func IsBetween ¶
IsBetween checks if t is between start and end (inclusive).
func IsCurrentLeapYear ¶
func IsCurrentLeapYear() bool
IsCurrentLeapYear checks if the current year is a leap year.
func IsLeapYear ¶
IsLeapYear checks if the given year is a leap year.
func IsLocal ¶
IsLocal checks if the given time is in the local time zone.
func IsSameDay ¶
IsSameDay checks if t1 and t2 are on the same day.
func IsSameMonth ¶
IsSameMonth checks if t1 and t2 are in the same month.
func IsSameYear ¶
IsSameYear checks if t1 and t2 are in the same year.
func IsValidDate ¶
IsValidDate checks if the given year, month, and day form a valid date.
func IsValidDateTime ¶
IsValidDateTime checks if the given date and time components form a valid date and time.
func IsValidTime ¶
IsValidTime checks if the given hour, minute, and second form a valid time.
func IsWeekday ¶
IsWeekday checks if the given time is on a weekday (Monday to Friday).
func IsWeekend ¶
IsWeekend checks if the given time is on a weekend (Saturday or Sunday).
func MonthsBetween ¶
MonthsBetween calculates the approximate number of months between two times.
func MustParseLong ¶
MustParseLong parses a datetime string (format: "2006-01-02 15:04:05") into a time.Time object. Panics if parsing fails.
func MustParseShort ¶
MustParseShort parses a date string (format: "2006-01-02") into a time.Time object. Panics if parsing fails.
func ParseDateCompact ¶
ParseDateCompact parses a compact date string (format: "20060102") into a time.Time object. Returns the parsed time and any error that occurred during parsing.
func ParseDatetimeCompact ¶
ParseDatetimeCompact parses a compact datetime string (format: "20060102150405") into a time.Time object. Returns the parsed time and any error that occurred during parsing.
func ParseISO8601 ¶
ParseISO8601 parses an ISO8601 formatted time string into a time.Time object. Returns the parsed time and any error that occurred during parsing.
func ParseLong ¶
ParseLong parses a datetime string (format: "2006-01-02 15:04:05") into a time.Time object. Returns the parsed time and any error that occurred during parsing.
func ParseShort ¶
ParseShort parses a date string (format: "2006-01-02") into a time.Time object. Returns the parsed time and any error that occurred during parsing.
func ParseUTC ¶
ParseUTC parses a UTC time string into a local time.Time object.
func ParseUnix ¶
ParseUnix converts a Unix timestamp (seconds since epoch) to a time.Time object.
func ParseUnixMilli ¶
ParseUnixMilli converts a Unix timestamp in milliseconds to a time.Time object.
func ParseWithLayout ¶
ParseWithLayout parses a time string using the specified layout. Returns the parsed time and any error that occurred during parsing.
func SleepDuration ¶
SleepDuration sleeps for the specified duration.
func SleepMicrosecond ¶
func SleepMicrosecond(sleep int)
SleepMicrosecond sleeps for a specified number of microseconds.
func SleepMillisecond ¶
func SleepMillisecond(sleep int)
SleepMillisecond sleeps for a specified number of milliseconds.
func SleepRandMilli ¶
func SleepRandMilli(max int)
SleepRandMilli sleeps for a random number of milliseconds up to the specified maximum. Uses the current time as a seed for the random number generator.
func SleepRandMilliWithSeed ¶
SleepRandMilliWithSeed sleeps for a random number of milliseconds up to the specified maximum. Uses the provided seed for the random number generator.
func SleepRandSecond ¶
func SleepRandSecond(max int)
SleepRandSecond sleeps for a random number of seconds up to the specified maximum. Uses the current time as a seed for the random number generator.
func SleepRandSecondWithSeed ¶
SleepRandSecondWithSeed sleeps for a random number of seconds up to the specified maximum. Uses the provided seed for the random number generator.
func SleepSecond ¶
func SleepSecond(sleep int)
SleepSecond sleeps for a specified number of seconds.
func SleepUntil ¶
SleepUntil sleeps until the specified time. If the specified time is in the past, it returns immediately.
func StartOfDay ¶
StartOfDay returns the start of the day (00:00:00) for the given time.
func StartOfMonth ¶
StartOfMonth returns the start of the month (1st day 00:00:00) for the given time.
func StartOfQuarter ¶
StartOfQuarter returns the start of the quarter for the given time.
func StartOfWeek ¶
StartOfWeek returns the start of the week (Monday 00:00:00) for the given time.
func StartOfYear ¶
StartOfYear returns the start of the year (January 1st 00:00:00) for the given time.
func SubtractDays ¶
SubtractDays subtracts the specified number of days from the given time.
func SubtractHours ¶
SubtractHours subtracts the specified number of hours from the given time.
func SubtractMinutes ¶
SubtractMinutes subtracts the specified number of minutes from the given time.
func SubtractMonths ¶
SubtractMonths subtracts the specified number of months from the given time.
func SubtractSeconds ¶
SubtractSeconds subtracts the specified number of seconds from the given time.
func SubtractYears ¶
SubtractYears subtracts the specified number of years from the given time.
func WeekdayEn2Cn ¶
WeekdayEn2Cn converts English weekday names to Chinese.
func WeekdayToCn ¶
WeekdayToCn converts time.Weekday to Chinese weekday name.
Types ¶
This section is empty.
Source Files
¶
- calc.go
- const.go
- format.go
- parse.go
- sleep.go
- util.go
- weekday.go
- zone.go