Documentation
¶
Overview ¶
Package timeutil provides centralized timezone handling for the application. Call LoadLocation once during initialization to set the canonical timezone, then use Now() and Location() throughout business logic instead of time.Now() and time.Local.
Index ¶
- func AddTime(unit string, quantity int64, baseTime ...time.Time) time.Time
- func DayDiff(startTime, endTime time.Time) int64
- func DaysToMonthDay(t time.Time, targetDay int) int64
- func DaysToNextMonth(t time.Time) int64
- func DaysToYearDay(t time.Time, month int, day int) int64
- func FormatDate(t time.Time) string
- func GetLastDayOfMonth(t time.Time) int64
- func GetYearDays(t time.Time, month int, day int) int64
- func InLoc(t time.Time) time.Time
- func LoadLocation(tzName string) error
- func Location() *time.Location
- func LocationName() string
- func MonthDiff(startTime, endTime time.Time) int
- func Now() time.Time
- func ParseDate(s string) (time.Time, error)
- func TodayEnd() time.Time
- func TodayStart() time.Time
- func UnixMilli(t time.Time) int64
- func YearDiff(startTime, endTime time.Time) int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DaysToNextMonth ¶ added in v1.20.2
func FormatDate ¶
FormatDate formats a time as "2006-01-02" in the application timezone.
func GetLastDayOfMonth ¶ added in v1.20.2
GetLastDayOfMonth 获取指定时间所在月份的最后一天
func LoadLocation ¶
LoadLocation loads the timezone by name (e.g., "Asia/Shanghai", "UTC"). Must be called once at startup before any other function in this package.
func Location ¶
Location returns the canonical application timezone. Falls back to time.Local if LoadLocation was never called.
func Now ¶
Now returns the current time in the application timezone. Falls back to time.Now() if LoadLocation was never called.
func TodayStart ¶
TodayStart returns the start of today (00:00:00) in the application timezone.
Types ¶
This section is empty.