xlfbUtilTime

package
v0.0.0-...-b5383aa Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
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"
)
View Source
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

func AddDays(t time.Time, days int) time.Time

AddDays adds the specified number of days to the given time.

func AddHours

func AddHours(t time.Time, hours int) time.Time

AddHours adds the specified number of hours to the given time.

func AddMinutes

func AddMinutes(t time.Time, minutes int) time.Time

AddMinutes adds the specified number of minutes to the given time.

func AddMonths

func AddMonths(t time.Time, months int) time.Time

AddMonths adds the specified number of months to the given time.

func AddSeconds

func AddSeconds(t time.Time, seconds int) time.Time

AddSeconds adds the specified number of seconds to the given time.

func AddYears

func AddYears(t time.Time, years int) time.Time

AddYears adds the specified number of years to the given time.

func ConvertTimeZone

func ConvertTimeZone(t time.Time, fromZone, toZone string) (time.Time, error)

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

func DaysBetween(t1, t2 time.Time) int

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

func DaysInMonth(year int, month time.Month) int

DaysInMonth returns the number of days in the given month and year.

func EndOfDay

func EndOfDay(t time.Time) time.Time

EndOfDay returns the end of the day (23:59:59.999999999) for the given time.

func EndOfMonth

func EndOfMonth(t time.Time) time.Time

EndOfMonth returns the end of the month (last day 23:59:59.999999999) for the given time.

func EndOfQuarter

func EndOfQuarter(t time.Time) time.Time

EndOfQuarter returns the end of the quarter for the given time.

func EndOfWeek

func EndOfWeek(t time.Time) time.Time

EndOfWeek returns the end of the week (Sunday 23:59:59.999999999) for the given time.

func EndOfYear

func EndOfYear(t time.Time) time.Time

EndOfYear returns the end of the year (December 31st 23:59:59.999999999) for the given time.

func FormatDelay

func FormatDelay(ts time.Time) string

FormatDelay returns a string representation of the time elapsed since the given timestamp.

func FormatDuration

func FormatDuration(d time.Duration) string

FormatDuration formats a duration to a human-readable string.

func FormatNow

func FormatNow(layout string) string

FormatNow formats the current time according to the specified layout.

func FormatTimeLocal

func FormatTimeLocal(t time.Time, layout string) string

FormatTimeLocal formats the given time in the local time zone according to the specified layout.

func FormatTimeUTC

func FormatTimeUTC(t time.Time, layout string) string

FormatTimeUTC formats the given time in UTC according to the specified layout.

func FormatTimeWithLayout

func FormatTimeWithLayout(t time.Time, layout string) string

FormatTimeWithLayout formats the given time.Time according to the specified layout.

func FormatUnix

func FormatUnix(unixTime interface{}, format string) string

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

func GetAge(birthdate, reference time.Time) int

GetAge calculates the age in years based on the birthdate and the reference date.

func GetCurrentAge

func GetCurrentAge(birthdate time.Time) int

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

func GetCurrentWeekday() time.Weekday

GetCurrentWeekday returns the current weekday.

func GetCurrentWeekdayCn

func GetCurrentWeekdayCn() string

GetCurrentWeekdayCn returns the current weekday in Chinese.

func GetDayOfYear

func GetDayOfYear(t time.Time) int

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

func GetDaysInYear(year int) int

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

func GetElapsedDaysInYear(t time.Time) int

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

func GetElapsedPercentageOfYear(t time.Time) float64

GetElapsedPercentageOfYear returns the percentage of the year that has elapsed for the given time.

func GetNextWeekday

func GetNextWeekday(t time.Time, weekday time.Weekday) time.Time

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

func GetPreviousWeekday(t time.Time, weekday time.Weekday) time.Time

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

func GetQuarter(t time.Time) int

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

func GetRemainingDaysInYear(t time.Time) int

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

func GetRemainingPercentageOfYear(t time.Time) float64

GetRemainingPercentageOfYear returns the percentage of the year that remains for the given time.

func GetTimeInLocation

func GetTimeInLocation(t time.Time, location *time.Location) time.Time

GetTimeInLocation returns the given time in the specified location.

func GetTimeInLocationName

func GetTimeInLocationName(t time.Time, locationName string) (time.Time, error)

GetTimeInLocationName returns the given time in the specified location name.

func GetTimeZone

func GetTimeZone(t time.Time) string

GetTimeZone returns the name of the time zone for the given time.

func GetTimeZoneOffset

func GetTimeZoneOffset(t time.Time) int

GetTimeZoneOffset returns the offset in seconds east of UTC for the given time.

func GetUTCOffset

func GetUTCOffset(t time.Time) float64

GetUTCOffset returns the offset between the given time and UTC in hours.

func GetUTCOffsetString

func GetUTCOffsetString(t time.Time) string

GetUTCOffsetString returns the offset between the given time and UTC as a string (e.g., "+08:00").

func GetUTCTime

func GetUTCTime() time.Time

GetUTCTime returns the current time in UTC.

func GetWeekOfYear

func GetWeekOfYear(t time.Time) int

GetWeekOfYear returns the ISO 8601 week number (1-53) for the given time.

func GetWeekday

func GetWeekday(t time.Time) time.Weekday

GetWeekday returns the weekday of the given time.

func GetWeekdayCn

func GetWeekdayCn(t time.Time) string

GetWeekdayCn returns the Chinese name of the weekday for the given time.

func GetWeekdayName

func GetWeekdayName(t time.Time) string

GetWeekdayName returns the English name of the weekday for the given time.

func IsAfter

func IsAfter(t1, t2 time.Time) bool

IsAfter checks if t1 is after t2.

func IsBefore

func IsBefore(t1, t2 time.Time) bool

IsBefore checks if t1 is before t2.

func IsBetween

func IsBetween(t, start, end time.Time) bool

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 IsEqual

func IsEqual(t1, t2 time.Time) bool

IsEqual checks if t1 is equal to t2.

func IsLeapYear

func IsLeapYear(year int) bool

IsLeapYear checks if the given year is a leap year.

func IsLocal

func IsLocal(t time.Time) bool

IsLocal checks if the given time is in the local time zone.

func IsSameDay

func IsSameDay(t1, t2 time.Time) bool

IsSameDay checks if t1 and t2 are on the same day.

func IsSameMonth

func IsSameMonth(t1, t2 time.Time) bool

IsSameMonth checks if t1 and t2 are in the same month.

func IsSameYear

func IsSameYear(t1, t2 time.Time) bool

IsSameYear checks if t1 and t2 are in the same year.

func IsUTC

func IsUTC(t time.Time) bool

IsUTC checks if the given time is in UTC.

func IsValidDate

func IsValidDate(year, month, day int) bool

IsValidDate checks if the given year, month, and day form a valid date.

func IsValidDateTime

func IsValidDateTime(year, month, day, hour, minute, second int) bool

IsValidDateTime checks if the given date and time components form a valid date and time.

func IsValidTime

func IsValidTime(hour, minute, second int) bool

IsValidTime checks if the given hour, minute, and second form a valid time.

func IsWeekday

func IsWeekday(t time.Time) bool

IsWeekday checks if the given time is on a weekday (Monday to Friday).

func IsWeekend

func IsWeekend(t time.Time) bool

IsWeekend checks if the given time is on a weekend (Saturday or Sunday).

func MonthsBetween

func MonthsBetween(t1, t2 time.Time) int

MonthsBetween calculates the approximate number of months between two times.

func MustParseLong

func MustParseLong(s string) time.Time

MustParseLong parses a datetime string (format: "2006-01-02 15:04:05") into a time.Time object. Panics if parsing fails.

func MustParseShort

func MustParseShort(s string) time.Time

MustParseShort parses a date string (format: "2006-01-02") into a time.Time object. Panics if parsing fails.

func ParseDateCompact

func ParseDateCompact(s string) (time.Time, error)

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

func ParseDatetimeCompact(s string) (time.Time, error)

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

func ParseISO8601(s string) (time.Time, error)

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

func ParseLong(s string) (time.Time, error)

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

func ParseShort(s string) (time.Time, error)

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

func ParseUTC(utc string, format string) (local time.Time, err error)

ParseUTC parses a UTC time string into a local time.Time object.

func ParseUnix

func ParseUnix(timestamp int64) time.Time

ParseUnix converts a Unix timestamp (seconds since epoch) to a time.Time object.

func ParseUnixMilli

func ParseUnixMilli(timestamp int64) time.Time

ParseUnixMilli converts a Unix timestamp in milliseconds to a time.Time object.

func ParseWithLayout

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

ParseWithLayout parses a time string using the specified layout. Returns the parsed time and any error that occurred during parsing.

func SleepDuration

func SleepDuration(d time.Duration)

SleepDuration sleeps for the specified duration.

func SleepHour

func SleepHour()

SleepHour sleeps for one hour.

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 SleepMinute

func SleepMinute()

SleepMinute sleeps for one minute.

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

func SleepRandMilliWithSeed(max int, seed int64)

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

func SleepRandSecondWithSeed(max int, seed int64)

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

func SleepUntil(t time.Time)

SleepUntil sleeps until the specified time. If the specified time is in the past, it returns immediately.

func StartOfDay

func StartOfDay(t time.Time) time.Time

StartOfDay returns the start of the day (00:00:00) for the given time.

func StartOfMonth

func StartOfMonth(t time.Time) time.Time

StartOfMonth returns the start of the month (1st day 00:00:00) for the given time.

func StartOfQuarter

func StartOfQuarter(t time.Time) time.Time

StartOfQuarter returns the start of the quarter for the given time.

func StartOfWeek

func StartOfWeek(t time.Time) time.Time

StartOfWeek returns the start of the week (Monday 00:00:00) for the given time.

func StartOfYear

func StartOfYear(t time.Time) time.Time

StartOfYear returns the start of the year (January 1st 00:00:00) for the given time.

func SubtractDays

func SubtractDays(t time.Time, days int) time.Time

SubtractDays subtracts the specified number of days from the given time.

func SubtractHours

func SubtractHours(t time.Time, hours int) time.Time

SubtractHours subtracts the specified number of hours from the given time.

func SubtractMinutes

func SubtractMinutes(t time.Time, minutes int) time.Time

SubtractMinutes subtracts the specified number of minutes from the given time.

func SubtractMonths

func SubtractMonths(t time.Time, months int) time.Time

SubtractMonths subtracts the specified number of months from the given time.

func SubtractSeconds

func SubtractSeconds(t time.Time, seconds int) time.Time

SubtractSeconds subtracts the specified number of seconds from the given time.

func SubtractYears

func SubtractYears(t time.Time, years int) time.Time

SubtractYears subtracts the specified number of years from the given time.

func ToLocal

func ToLocal(t time.Time) time.Time

ToLocal converts a time to the local time zone.

func ToUTC

func ToUTC(t time.Time) time.Time

ToUTC converts a time to UTC.

func WeekdayEn2Cn

func WeekdayEn2Cn(s string) string

WeekdayEn2Cn converts English weekday names to Chinese.

func WeekdayToCn

func WeekdayToCn(w time.Weekday) string

WeekdayToCn converts time.Weekday to Chinese weekday name.

func YearsBetween

func YearsBetween(t1, t2 time.Time) int

YearsBetween calculates the number of years between two times.

Types

This section is empty.

Source Files

  • calc.go
  • const.go
  • format.go
  • parse.go
  • sleep.go
  • util.go
  • weekday.go
  • zone.go

Jump to

Keyboard shortcuts

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