xtime

package
v2.6.2 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: MIT Imports: 5 Imported by: 20

Documentation

Index

Constants

View Source
const (
	Layout      = time.Layout // The reference time, in numerical order.
	ANSIC       = time.ANSIC
	UnixDate    = time.UnixDate
	RubyDate    = time.RubyDate
	RFC822      = time.RFC822
	RFC822Z     = time.RFC822Z
	RFC850      = time.RFC850
	RFC1123     = time.RFC1123
	RFC1123Z    = time.RFC1123Z
	RFC3339     = time.RFC3339
	RFC3339Nano = time.RFC3339Nano
	Kitchen     = time.Kitchen

	Stamp      = time.Stamp
	StampMilli = time.StampMilli
	StampMicro = time.StampMicro
	StampNano  = time.StampNano
	DateTime   = time.DateTime
	DateOnly   = time.DateOnly
	TimeOnly   = time.TimeOnly
	MonthOnly  = "2006-01"
	YearOnly   = "2006"
)
View Source
const (
	TimeFormat     = "H:i:s"
	DateFormat     = "Y-m-d"
	DatetimeFormat = "Y-m-d H:i:s"
)

Variables

This section is empty.

Functions

func GetLocation added in v2.6.0

func GetLocation() *time.Location

GetLocation returns the currently used time zone.

func IsLeapYear added in v2.3.3

func IsLeapYear(year int) bool

IsLeapYear reports whether year is a leap year.

func SetLocation added in v2.5.3

func SetLocation(loc *time.Location)

SetLocation sets the time zone. It is safe for concurrent use.

func Transform

func Transform(t Time, rule ...[]TransformRule) string

Transform renders t as a human-readable string relative to the current time. The optional rule provides a custom set of TransformRule values in place of the default rules.

Types

type Time added in v2.1.1

type Time = time.Time

Time is an alias of time.Time.

func Day added in v2.1.0

func Day(offset ...int) Time

Day returns the current time shifted by the given number of days. For example, -1 is the previous day, 0 is the current day and 1 is the next day.

func DayHead added in v2.1.0

func DayHead(offset ...int) Time

DayHead returns the first second of the day, shifted by offset days.

func DayTail added in v2.1.0

func DayTail(offset ...int) Time

DayTail returns the last second of the day, shifted by offset days.

func Month added in v2.1.0

func Month(offset ...int) Time

Month returns the current time shifted by the given number of months. For example, -1 is the previous month, 0 is the current month and 1 is the next month.

func MonthHead added in v2.1.0

func MonthHead(offset ...int) Time

MonthHead returns the first second of the first day of the month, shifted by offset months.

func MonthTail added in v2.1.0

func MonthTail(offset ...int) Time

MonthTail returns the last second of the last day of the month, shifted by offset months.

func Now

func Now() Time

Now returns the current time in the current time zone.

func Parse added in v2.1.0

func Parse(layout string, value string) (Time, error)

Parse parses a date-time string with the given layout in the current time zone.

func Today

func Today() Time

Today returns the current time.

func Tomorrow

func Tomorrow() Time

Tomorrow returns the same time of day tomorrow.

func Unix

func Unix(sec int64, nsec ...int64) Time

Unix returns the local time corresponding to the given Unix time in seconds. The optional nsec is the nanosecond offset.

func UnixMicro

func UnixMicro(usec int64) Time

UnixMicro returns the local time corresponding to the given Unix time in microseconds.

func UnixMilli

func UnixMilli(msec int64) Time

UnixMilli returns the local time corresponding to the given Unix time in milliseconds.

func UnixNano

func UnixNano(nsec int64) Time

UnixNano returns the local time corresponding to the given Unix time in nanoseconds.

func Week added in v2.1.0

func Week(offset ...int) Time

Week returns the current time shifted by the given number of weeks. For example, -1 is the previous week, 0 is the current week and 1 is the next week.

func WeekHead added in v2.1.0

func WeekHead(offset ...int) Time

WeekHead returns the first second of the first day of the week, with Monday as the first day. offset shifts the result by whole weeks.

func WeekTail added in v2.1.0

func WeekTail(offset ...int) Time

WeekTail returns the last second of the last day of the week, with Sunday as the last day. offset shifts the result by whole weeks.

func Yesterday

func Yesterday() Time

Yesterday returns the same time of day yesterday.

type TransformRule

type TransformRule struct {
	Max       uint   // Upper time bound in seconds, 0 means no upper bound
	PastTpl   string // Display template for a time in the past
	FutureTpl string // Display template for a time in the future
}

TransformRule describes how a time difference is rendered into a human-readable string.

Jump to

Keyboard shortcuts

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