datetime

package
v1.15.0 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DayInSeconds   = 24 * 60 * 60
	WeekInSeconds  = 7 * DayInSeconds
	MonthInSeconds = 30 * DayInSeconds
	YearInSeconds  = 365 * DayInSeconds

	DayInMinutes   = 24 * 60
	WeekInMinutes  = 7 * DayInMinutes
	MonthInMinutes = 30 * DayInMinutes
	YearInMinutes  = 365 * DayInMinutes
)

Common time constants

View Source
const (
	DateFormat          = "2006-01-02"
	TimeFormat          = "15:04:05"
	DateTimeFormat      = "2006-01-02 15:04:05"
	ISO8601Format       = "2006-01-02T15:04:05Z07:00"
	RFC3339Format       = time.RFC3339
	TimestampFormat     = "20060102150405"
	HumanDateFormat     = "January 2, 2006"
	HumanTimeFormat     = "3:04 PM"
	HumanDateTimeFormat = "January 2, 2006 at 3:04 PM"
)

Common time formats

Variables

This section is empty.

Functions

func AddBusinessDays

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

AddBusinessDays adds business days to a date (skipping weekends)

func Age

func Age(birthDate time.Time) int

Age calculates the age in years from the given birth date

func BusinessDaysBetween

func BusinessDaysBetween(start, end time.Time) int

BusinessDaysBetween calculates the number of business days between two dates

func DaysBetween

func DaysBetween(start, end time.Time) int

DaysBetween calculates the number of days between two dates

func DaysInMonth

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

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

func EndOfMonth

func EndOfMonth(t time.Time) time.Time

EndOfMonth returns the end of the month 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) for the given time

func EndOfYear

func EndOfYear(t time.Time) time.Time

EndOfYear returns the end of the year for the given time

func FormatDuration

func FormatDuration(d time.Duration) string

FormatDuration formats a duration in human-readable format

func FromUnixMillis

func FromUnixMillis(millis int64) time.Time

FromUnixMillis converts Unix timestamp in milliseconds to time

func FromUnixTimestamp

func FromUnixTimestamp(timestamp int64) time.Time

FromUnixTimestamp converts Unix timestamp to time

func GetQuarter

func GetQuarter(t time.Time) int

GetQuarter returns the quarter (1-4) for the given time

func InTimeRange

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

InTimeRange checks if a time is within the given range (inclusive)

func IsFuture

func IsFuture(t time.Time) bool

IsFuture checks if the given time is in the future

func IsLeapYear

func IsLeapYear(year int) bool

IsLeapYear checks if the given year is a leap year

func IsPast

func IsPast(t time.Time) bool

IsPast checks if the given time is in the past

func IsToday

func IsToday(t time.Time) bool

IsToday checks if the given time is today

func IsTomorrow

func IsTomorrow(t time.Time) bool

IsTomorrow checks if the given time is tomorrow

func IsWeekday

func IsWeekday(t time.Time) bool

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

func IsWeekend

func IsWeekend(t time.Time) bool

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

func IsYesterday

func IsYesterday(t time.Time) bool

IsYesterday checks if the given time is yesterday

func Max

func Max(t1, t2 time.Time) time.Time

Max returns the later of two times

func Min

func Min(t1, t2 time.Time) time.Time

Min returns the earlier of two times

func Now

func Now() time.Time

Now returns the current time

func NowUTC

func NowUTC() time.Time

NowUTC returns the current time in UTC

func ParseDate

func ParseDate(dateStr string) (time.Time, error)

ParseDate parses a date string using common formats

func Round

func Round(t time.Time, d time.Duration) time.Time

Round rounds time to the nearest duration

func StartOfMonth

func StartOfMonth(t time.Time) time.Time

StartOfMonth returns the start of the month 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) for the given time

func StartOfYear

func StartOfYear(t time.Time) time.Time

StartOfYear returns the start of the year for the given time

func TimeAgo

func TimeAgo(t time.Time) string

TimeAgo returns a human-readable string representing how long ago the time was

func TimeUntil

func TimeUntil(t time.Time) string

TimeUntil returns a human-readable string representing how long until the time

func ToUnixMillis

func ToUnixMillis(t time.Time) int64

ToUnixMillis converts time to Unix timestamp in milliseconds

func ToUnixTimestamp

func ToUnixTimestamp(t time.Time) int64

ToUnixTimestamp converts time to Unix timestamp

func Today

func Today() time.Time

Today returns today's date at midnight

func TodayUTC

func TodayUTC() time.Time

TodayUTC returns today's date at midnight in UTC

func Tomorrow

func Tomorrow() time.Time

Tomorrow returns tomorrow's date at midnight

func Truncate

func Truncate(t time.Time, d time.Duration) time.Time

Truncate truncates time to the specified duration

func Yesterday

func Yesterday() time.Time

Yesterday returns yesterday's date at midnight

Types

This section is empty.

Jump to

Keyboard shortcuts

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