Documentation
¶
Index ¶
- Constants
- func GetLocation() *time.Location
- func IsLeapYear(year int) bool
- func SetLocation(loc *time.Location)
- func Transform(t Time, rule ...[]TransformRule) string
- type Time
- func Day(offset ...int) Time
- func DayHead(offset ...int) Time
- func DayTail(offset ...int) Time
- func Month(offset ...int) Time
- func MonthHead(offset ...int) Time
- func MonthTail(offset ...int) Time
- func Now() Time
- func Parse(layout string, value string) (Time, error)
- func Today() Time
- func Tomorrow() Time
- func Unix(sec int64, nsec ...int64) Time
- func UnixMicro(usec int64) Time
- func UnixMilli(msec int64) Time
- func UnixNano(nsec int64) Time
- func Week(offset ...int) Time
- func WeekHead(offset ...int) Time
- func WeekTail(offset ...int) Time
- func Yesterday() Time
- type TransformRule
Constants ¶
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" )
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
GetLocation returns the currently used time zone.
func IsLeapYear ¶ added in v2.3.3
IsLeapYear reports whether year is a leap year.
func SetLocation ¶ added in v2.5.3
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
Time is an alias of time.Time.
func Day ¶ added in v2.1.0
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 Month ¶ added in v2.1.0
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
MonthHead returns the first second of the first day of the month, shifted by offset months.
func MonthTail ¶ added in v2.1.0
MonthTail returns the last second of the last day of the month, shifted by offset months.
func Parse ¶ added in v2.1.0
Parse parses a date-time string with the given layout in the current time zone.
func Unix ¶
Unix returns the local time corresponding to the given Unix time in seconds. The optional nsec is the nanosecond offset.
func UnixMicro ¶
UnixMicro returns the local time corresponding to the given Unix time in microseconds.
func UnixMilli ¶
UnixMilli returns the local time corresponding to the given Unix time in milliseconds.
func UnixNano ¶
UnixNano returns the local time corresponding to the given Unix time in nanoseconds.
func Week ¶ added in v2.1.0
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
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.
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.