Expand description
Package time provides functionality for measuring and displaying time. The calendrical calculations always assume a Gregorian calendar, with no leap seconds.
zh-cn
time包提供了时间的显示和测量用的函数。日历的计算采用的是公历。Structs§
- Duration
- A Duration represents the elapsed time between two instants as an int64 nanosecond count. The representation limits the largest representable duration to approximately 290 years.
- Local
- Local represents the system’s local time zone. On Unix systems, Local consults the TZ environment variable to find the time zone to use. No TZ means use the system default /etc/localtime. TZ=“” means use UTC. TZ=“foo” means use file foo in the system timezone directory.
- Location
- A Location maps time instants to the zone in use at that time. Typically, the Location represents the collection of time offsets in use in a geographical area. For many Locations the time offset varies depending on whether daylight savings time is in use at the time instant.
- Time
- A Time represents an instant in time with nanosecond precision. Programs using times should typically store and pass them as values, not pointers. That is, time variables and struct fields should be of type time.Time, not *time.Time.
- UTC
- UTC represents Universal Coordinated Time (UTC).
Enums§
- Month
- A Month specifies a month of the year (January = 1, …).
- Weekday
- A Weekday specifies a day of the week (Sunday = 0, …).
Constants§
- ANSIC
- Time Format - ANSIC
- Hour
- Time Unit Hour
- Kitchen
- Time Format - Kitchen
- Layout
- Time Format - Layout
- Microsecond
- Time Unit Microsecond
- Millisecond
- Time Unit Millisecond
- Minute
- Time Unit Minute
- Nanosecond
- Time Unit Nanosecond
- RFC822
- Time Format - RFC822
- RFC850
- Time Format - RFC850
- RFC822Z
- Time Format - RFC822Z
- RFC1123
- Time Format - RFC1123
- RFC3339
- Time Format - RFC3339
- RFC1123Z
- Time Format - RFC1123Z
- RFC3339
Nano - Time Format - RFC3339Nano
- Ruby
Date - Time Format - RubyDate
- Second
- Time Unit Second
- Stamp
- Handy time stamps.
- Stamp
Micro - Handy time StampMicro.
- Stamp
Milli - Handy time StampMilli.
- Stamp
Nano - Handy time StampNano.
- Unix
Date - Time Format - UnixDate
Functions§
- Date
- Date returns the Time corresponding to
- Fixed
Zone - FixedZone returns a Location that always uses the given zone name and offset (seconds east of UTC).
- Load
Location - LoadLocation returns the Location with the given name.
- Now
- Now returns the current local time.
- Parse
- Parse parses a formatted string and returns the time value it represents. See the documentation for the constant called Layout to see how to represent the format. The second argument must be parseable using the format string (layout) provided as the first argument.
- Parse
Duration - ParseDuration parses a duration string. A duration string is a possibly signed sequence of decimal numbers, each with optional fraction and a unit suffix, such as “300ms”, “-1.5h” or “2h45m”. Valid time units are “ns”, “us” (or “µs”), “ms”, “s”, “m”, “h”.
- Parse
InLocation - ParseInLocation is like Parse but differs in two important ways. First, in the absence of time zone information, Parse interprets a time as UTC; ParseInLocation interprets the time as in the given location. Second, when given a zone offset or abbreviation, Parse tries to match it against the Local location; ParseInLocation uses the given location.
- Since
- Since returns the time elapsed since t. It is shorthand for time.Now().Sub(t).
- Unix
- Unix returns the local Time corresponding to the given Unix time, sec seconds and nsec nanoseconds since January 1, 1970 UTC. It is valid to pass nsec outside the range [0, 999999999]. Not all sec values have a corresponding time value. One such value is 1<<63-1 (the largest int64 value).
- Unix
Micro - UnixMicro returns the local Time corresponding to the given Unix time, usec microseconds since January 1, 1970 UTC.
- Unix
Milli - UnixMilli returns the local Time corresponding to the given Unix time, msec milliseconds since January 1, 1970 UTC.
- Until
- Until returns the duration until t. It is shorthand for t.Sub(time.Now()).