package time

Import Path
	time (on golang.org and go.dev)

Dependency Relation
	imports 5 packages, and imported by 34 packages

Involved Source Files
	    format.go
	    sleep.go
	    sys_unix.go
	    tick.go
	d-> time.go
	    zoneinfo.go
	    zoneinfo_read.go
	    zoneinfo_unix.go

Exported Type Names

type Duration int64 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. (T) Hours() float64 (T) Microseconds() int64 (T) Milliseconds() int64 (T) Minutes() float64 (T) Nanoseconds() int64 (T) Round(m Duration) Duration (T) Seconds() float64 (T) String() string (T) Truncate(m Duration) Duration T : expvar.Var T : fmt.Stringer func ParseDuration(s string) (Duration, error) func Since(t Time) Duration func Until(t Time) Duration func Duration.Round(m Duration) Duration func Duration.Truncate(m Duration) Duration func Time.Sub(u Time) Duration func flag.Duration(name string, value Duration, usage string) *Duration func flag.(*FlagSet).Duration(name string, value Duration, usage string) *Duration func os.(*ProcessState).SystemTime() Duration func os.(*ProcessState).UserTime() Duration func After(d Duration) <-chan Time func AfterFunc(d Duration, f func()) *Timer func NewTicker(d Duration) *Ticker func NewTimer(d Duration) *Timer func Sleep(d Duration) func Tick(d Duration) <-chan Time func Duration.Round(m Duration) Duration func Duration.Truncate(m Duration) Duration func (*Ticker).Reset(d Duration) func Time.Add(d Duration) Time func Time.Round(d Duration) Time func Time.Truncate(d Duration) Time func (*Timer).Reset(d Duration) bool func context.WithTimeout(parent context.Context, timeout Duration) (context.Context, context.CancelFunc) func database/sql.(*DB).SetConnMaxIdleTime(d Duration) func database/sql.(*DB).SetConnMaxLifetime(d Duration) func flag.Duration(name string, value Duration, usage string) *Duration func flag.DurationVar(p *Duration, name string, value Duration, usage string) func flag.DurationVar(p *Duration, name string, value Duration, usage string) func flag.(*FlagSet).Duration(name string, value Duration, usage string) *Duration func flag.(*FlagSet).DurationVar(p *Duration, name string, value Duration, usage string) func flag.(*FlagSet).DurationVar(p *Duration, name string, value Duration, usage string) func internal/trace.(*MMUCurve).Examples(window Duration, n int) (worst []trace.UtilWindow) func internal/trace.(*MMUCurve).MMU(window Duration) (mmu float64) func internal/trace.(*MMUCurve).MUD(window Duration, quantiles []float64) []float64 func net.DialTimeout(network, address string, timeout Duration) (net.Conn, error) func net.(*TCPConn).SetKeepAlivePeriod(d Duration) error func net/http.TimeoutHandler(h http.Handler, dt Duration, msg string) http.Handler const Hour const Microsecond const Millisecond const Minute const Nanosecond const Second
type Location (struct) 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. (*T) String() string *T : expvar.Var *T : fmt.Stringer func FixedZone(name string, offset int) *Location func LoadLocation(name string) (*Location, error) func LoadLocationFromTZData(name string, data []byte) (*Location, error) func Time.Location() *Location func Date(year int, month Month, day, hour, min, sec, nsec int, loc *Location) Time func ParseInLocation(layout, value string, loc *Location) (Time, error) func Time.In(loc *Location) Time var Local *Location var UTC *Location
type Month int A Month specifies a month of the year (January = 1, ...). (T) String() string T : expvar.Var T : fmt.Stringer func Time.Date() (year int, month Month, day int) func Time.Month() Month func Date(year int, month Month, day, hour, min, sec, nsec int, loc *Location) Time const April const August const December const February const January const July const June const March const May const November const October const September
type ParseError (struct) ParseError describes a problem parsing a time string. Layout string LayoutElem string Message string Value string ValueElem string (*T) Error() string *T : error
type Ticker (struct) A Ticker holds a channel that delivers `ticks' of a clock at intervals. C <-chan Time (*T) Reset(d Duration) (*T) Stop() func NewTicker(d Duration) *Ticker
type Time (struct) 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. A Time value can be used by multiple goroutines simultaneously except that the methods GobDecode, UnmarshalBinary, UnmarshalJSON and UnmarshalText are not concurrency-safe. Time instants can be compared using the Before, After, and Equal methods. The Sub method subtracts two instants, producing a Duration. The Add method adds a Time and a Duration, producing a Time. The zero value of type Time is January 1, year 1, 00:00:00.000000000 UTC. As this time is unlikely to come up in practice, the IsZero method gives a simple way of detecting a time that has not been initialized explicitly. Each Time has associated with it a Location, consulted when computing the presentation form of the time, such as in the Format, Hour, and Year methods. The methods Local, UTC, and In return a Time with a specific location. Changing the location in this way changes only the presentation; it does not change the instant in time being denoted and therefore does not affect the computations described in earlier paragraphs. Representations of a Time value saved by the GobEncode, MarshalBinary, MarshalJSON, and MarshalText methods store the Time.Location's offset, but not the location name. They therefore lose information about Daylight Saving Time. In addition to the required “wall clock” reading, a Time may contain an optional reading of the current process's monotonic clock, to provide additional precision for comparison or subtraction. See the “Monotonic Clocks” section in the package documentation for details. Note that the Go == operator compares not just the time instant but also the Location and the monotonic clock reading. Therefore, Time values should not be used as map or database keys without first guaranteeing that the identical Location has been set for all values, which can be achieved through use of the UTC or Local method, and that the monotonic clock reading has been stripped by setting t = t.Round(0). In general, prefer t.Equal(u) to t == u, since t.Equal uses the most accurate comparison available and correctly handles the case when only one of its arguments has a monotonic clock reading. (T) Add(d Duration) Time (T) AddDate(years int, months int, days int) Time (T) After(u Time) bool (T) AppendFormat(b []byte, layout string) []byte (T) Before(u Time) bool (T) Clock() (hour, min, sec int) (T) Date() (year int, month Month, day int) (T) Day() int (T) Equal(u Time) bool (T) Format(layout string) string (*T) GobDecode(data []byte) error (T) GobEncode() ([]byte, error) (T) Hour() int (T) ISOWeek() (year, week int) (T) In(loc *Location) Time (T) IsZero() bool (T) Local() Time (T) Location() *Location (T) MarshalBinary() ([]byte, error) (T) MarshalJSON() ([]byte, error) (T) MarshalText() ([]byte, error) (T) Minute() int (T) Month() Month (T) Nanosecond() int (T) Round(d Duration) Time (T) Second() int (T) String() string (T) Sub(u Time) Duration (T) Truncate(d Duration) Time (T) UTC() Time (T) Unix() int64 (T) UnixNano() int64 (*T) UnmarshalBinary(data []byte) error (*T) UnmarshalJSON(data []byte) error (*T) UnmarshalText(data []byte) error (T) Weekday() Weekday (T) Year() int (T) YearDay() int (T) Zone() (name string, offset int) T : encoding.BinaryMarshaler *T : encoding.BinaryUnmarshaler T : encoding.TextMarshaler *T : encoding.TextUnmarshaler *T : encoding/gob.GobDecoder T : encoding/gob.GobEncoder T : encoding/json.Marshaler *T : encoding/json.Unmarshaler T : expvar.Var T : fmt.Stringer func After(d Duration) <-chan Time func Date(year int, month Month, day, hour, min, sec, nsec int, loc *Location) Time func Now() Time func Parse(layout, value string) (Time, error) func ParseInLocation(layout, value string, loc *Location) (Time, error) func Tick(d Duration) <-chan Time func Unix(sec int64, nsec int64) Time func Time.Add(d Duration) Time func Time.AddDate(years int, months int, days int) Time func Time.In(loc *Location) Time func Time.Local() Time func Time.Round(d Duration) Time func Time.Truncate(d Duration) Time func Time.UTC() Time func archive/zip.(*FileHeader).ModTime() Time func context.Context.Deadline() (deadline Time, ok bool) func net/http.ParseTime(text string) (t Time, err error) func net/mail.ParseDate(date string) (Time, error) func net/mail.Header.Date() (Time, error) func os.FileInfo.ModTime() Time func testing.(*T).Deadline() (deadline Time, ok bool) func Since(t Time) Duration func Until(t Time) Duration func Time.After(u Time) bool func Time.Before(u Time) bool func Time.Equal(u Time) bool func Time.Sub(u Time) Duration func archive/zip.(*FileHeader).SetModTime(t Time) func context.WithDeadline(parent context.Context, d Time) (context.Context, context.CancelFunc) func crypto/tls.(*Conn).SetDeadline(t Time) error func crypto/tls.(*Conn).SetReadDeadline(t Time) error func crypto/tls.(*Conn).SetWriteDeadline(t Time) error func crypto/x509.(*Certificate).CreateCRL(rand io.Reader, priv interface{}, revokedCerts []pkix.RevokedCertificate, now, expiry Time) (crlBytes []byte, err error) func crypto/x509/pkix.(*CertificateList).HasExpired(now Time) bool func internal/poll.(*FD).SetDeadline(t Time) error func internal/poll.(*FD).SetReadDeadline(t Time) error func internal/poll.(*FD).SetWriteDeadline(t Time) error func net.Conn.SetDeadline(t Time) error func net.Conn.SetReadDeadline(t Time) error func net.Conn.SetWriteDeadline(t Time) error func net.PacketConn.SetDeadline(t Time) error func net.PacketConn.SetReadDeadline(t Time) error func net.PacketConn.SetWriteDeadline(t Time) error func net.(*TCPListener).SetDeadline(t Time) error func net.(*UnixListener).SetDeadline(t Time) error func net/http.ServeContent(w http.ResponseWriter, req *http.Request, name string, modtime Time, content io.ReadSeeker) func os.Chtimes(name string, atime Time, mtime Time) error func os.Chtimes(name string, atime Time, mtime Time) error func os.(*File).SetDeadline(t Time) error func os.(*File).SetReadDeadline(t Time) error func os.(*File).SetWriteDeadline(t Time) error func vendor/golang.org/x/crypto/cryptobyte.(*Builder).AddASN1GeneralizedTime(t Time) func vendor/golang.org/x/crypto/cryptobyte.(*String).ReadASN1GeneralizedTime(out *Time) bool
type Timer (struct) The Timer type represents a single event. When the Timer expires, the current time will be sent on C, unless the Timer was created by AfterFunc. A Timer must be created with NewTimer or AfterFunc. C <-chan Time (*T) Reset(d Duration) bool (*T) Stop() bool func AfterFunc(d Duration, f func()) *Timer func NewTimer(d Duration) *Timer
type Weekday int A Weekday specifies a day of the week (Sunday = 0, ...). (T) String() string T : expvar.Var T : fmt.Stringer func Time.Weekday() Weekday const Friday const Monday const Saturday const Sunday const Thursday const Tuesday const Wednesday
Exported Values
func After(d Duration) <-chan Time After waits for the duration to elapse and then sends the current time on the returned channel. It is equivalent to NewTimer(d).C. The underlying Timer is not recovered by the garbage collector until the timer fires. If efficiency is a concern, use NewTimer instead and call Timer.Stop if the timer is no longer needed.
func AfterFunc(d Duration, f func()) *Timer AfterFunc waits for the duration to elapse and then calls f in its own goroutine. It returns a Timer that can be used to cancel the call using its Stop method.
const ANSIC = "Mon Jan _2 15:04:05 2006" These are predefined layouts for use in Time.Format and time.Parse. The reference time used in the layouts is the specific time: Mon Jan 2 15:04:05 MST 2006 which is Unix time 1136239445. Since MST is GMT-0700, the reference time can be thought of as 01/02 03:04:05PM '06 -0700 To define your own format, write down what the reference time would look like formatted your way; see the values of constants like ANSIC, StampMicro or Kitchen for examples. The model is to demonstrate what the reference time looks like so that the Format and Parse methods can apply the same transformation to a general time value. Some valid layouts are invalid time values for time.Parse, due to formats such as _ for space padding and Z for zone information. Within the format string, an underscore _ represents a space that may be replaced by a digit if the following number (a day) has two digits; for compatibility with fixed-width Unix time formats. A decimal point followed by one or more zeros represents a fractional second, printed to the given number of decimal places. A decimal point followed by one or more nines represents a fractional second, printed to the given number of decimal places, with trailing zeros removed. When parsing (only), the input may contain a fractional second field immediately after the seconds field, even if the layout does not signify its presence. In that case a decimal point followed by a maximal series of digits is parsed as a fractional second. Numeric time zone offsets format as follows: -0700 ±hhmm -07:00 ±hh:mm -07 ±hh Replacing the sign in the format with a Z triggers the ISO 8601 behavior of printing Z instead of an offset for the UTC zone. Thus: Z0700 Z or ±hhmm Z07:00 Z or ±hh:mm Z07 Z or ±hh The recognized day of week formats are "Mon" and "Monday". The recognized month formats are "Jan" and "January". The formats 2, _2, and 02 are unpadded, space-padded, and zero-padded day of month. The formats __2 and 002 are space-padded and zero-padded three-character day of year; there is no unpadded day of year format. Text in the format string that is not recognized as part of the reference time is echoed verbatim during Format and expected to appear verbatim in the input to Parse. The executable example for Time.Format demonstrates the working of the layout string in detail and is a good reference. Note that the RFC822, RFC850, and RFC1123 formats should be applied only to local times. Applying them to UTC times will use "UTC" as the time zone abbreviation, while strictly speaking those RFCs require the use of "GMT" in that case. In general RFC1123Z should be used instead of RFC1123 for servers that insist on that format, and RFC3339 should be preferred for new protocols. RFC3339, RFC822, RFC822Z, RFC1123, and RFC1123Z are useful for formatting; when used with time.Parse they do not accept all the time formats permitted by the RFCs and they do accept time formats not formally defined. The RFC3339Nano format removes trailing zeros from the seconds field and thus may not sort correctly once formatted.
const April Month = 4
const August Month = 8
func Date(year int, month Month, day, hour, min, sec, nsec int, loc *Location) Time Date returns the Time corresponding to yyyy-mm-dd hh:mm:ss + nsec nanoseconds in the appropriate zone for that time in the given location. The month, day, hour, min, sec, and nsec values may be outside their usual ranges and will be normalized during the conversion. For example, October 32 converts to November 1. A daylight savings time transition skips or repeats times. For example, in the United States, March 13, 2011 2:15am never occurred, while November 6, 2011 1:15am occurred twice. In such cases, the choice of time zone, and therefore the time, is not well-defined. Date returns a time that is correct in one of the two zones involved in the transition, but it does not guarantee which. Date panics if loc is nil.
const December Month = 12
const February Month = 2
func FixedZone(name string, offset int) *Location FixedZone returns a Location that always uses the given zone name and offset (seconds east of UTC).
const Friday Weekday = 5
const Hour Duration = 3600000000000 Common durations. There is no definition for units of Day or larger to avoid confusion across daylight savings time zone transitions. To count the number of units in a Duration, divide: second := time.Second fmt.Print(int64(second/time.Millisecond)) // prints 1000 To convert an integer number of units to a Duration, multiply: seconds := 10 fmt.Print(time.Duration(seconds)*time.Second) // prints 10s
const January Month = 1
const July Month = 7
const June Month = 6
const Kitchen = "3:04PM" These are predefined layouts for use in Time.Format and time.Parse. The reference time used in the layouts is the specific time: Mon Jan 2 15:04:05 MST 2006 which is Unix time 1136239445. Since MST is GMT-0700, the reference time can be thought of as 01/02 03:04:05PM '06 -0700 To define your own format, write down what the reference time would look like formatted your way; see the values of constants like ANSIC, StampMicro or Kitchen for examples. The model is to demonstrate what the reference time looks like so that the Format and Parse methods can apply the same transformation to a general time value. Some valid layouts are invalid time values for time.Parse, due to formats such as _ for space padding and Z for zone information. Within the format string, an underscore _ represents a space that may be replaced by a digit if the following number (a day) has two digits; for compatibility with fixed-width Unix time formats. A decimal point followed by one or more zeros represents a fractional second, printed to the given number of decimal places. A decimal point followed by one or more nines represents a fractional second, printed to the given number of decimal places, with trailing zeros removed. When parsing (only), the input may contain a fractional second field immediately after the seconds field, even if the layout does not signify its presence. In that case a decimal point followed by a maximal series of digits is parsed as a fractional second. Numeric time zone offsets format as follows: -0700 ±hhmm -07:00 ±hh:mm -07 ±hh Replacing the sign in the format with a Z triggers the ISO 8601 behavior of printing Z instead of an offset for the UTC zone. Thus: Z0700 Z or ±hhmm Z07:00 Z or ±hh:mm Z07 Z or ±hh The recognized day of week formats are "Mon" and "Monday". The recognized month formats are "Jan" and "January". The formats 2, _2, and 02 are unpadded, space-padded, and zero-padded day of month. The formats __2 and 002 are space-padded and zero-padded three-character day of year; there is no unpadded day of year format. Text in the format string that is not recognized as part of the reference time is echoed verbatim during Format and expected to appear verbatim in the input to Parse. The executable example for Time.Format demonstrates the working of the layout string in detail and is a good reference. Note that the RFC822, RFC850, and RFC1123 formats should be applied only to local times. Applying them to UTC times will use "UTC" as the time zone abbreviation, while strictly speaking those RFCs require the use of "GMT" in that case. In general RFC1123Z should be used instead of RFC1123 for servers that insist on that format, and RFC3339 should be preferred for new protocols. RFC3339, RFC822, RFC822Z, RFC1123, and RFC1123Z are useful for formatting; when used with time.Parse they do not accept all the time formats permitted by the RFCs and they do accept time formats not formally defined. The RFC3339Nano format removes trailing zeros from the seconds field and thus may not sort correctly once formatted.
func LoadLocation(name string) (*Location, error) LoadLocation returns the Location with the given name. If the name is "" or "UTC", LoadLocation returns UTC. If the name is "Local", LoadLocation returns Local. Otherwise, the name is taken to be a location name corresponding to a file in the IANA Time Zone database, such as "America/New_York". The time zone database needed by LoadLocation may not be present on all systems, especially non-Unix systems. LoadLocation looks in the directory or uncompressed zip file named by the ZONEINFO environment variable, if any, then looks in known installation locations on Unix systems, and finally looks in $GOROOT/lib/time/zoneinfo.zip.
func LoadLocationFromTZData(name string, data []byte) (*Location, error) LoadLocationFromTZData returns a Location with the given name initialized from the IANA Time Zone database-formatted data. The data should be in the format of a standard IANA time zone file (for example, the content of /etc/localtime on Unix systems).
var Local *Location 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.
const March Month = 3
const May Month = 5
const Microsecond Duration = 1000 Common durations. There is no definition for units of Day or larger to avoid confusion across daylight savings time zone transitions. To count the number of units in a Duration, divide: second := time.Second fmt.Print(int64(second/time.Millisecond)) // prints 1000 To convert an integer number of units to a Duration, multiply: seconds := 10 fmt.Print(time.Duration(seconds)*time.Second) // prints 10s
const Millisecond Duration = 1000000 Common durations. There is no definition for units of Day or larger to avoid confusion across daylight savings time zone transitions. To count the number of units in a Duration, divide: second := time.Second fmt.Print(int64(second/time.Millisecond)) // prints 1000 To convert an integer number of units to a Duration, multiply: seconds := 10 fmt.Print(time.Duration(seconds)*time.Second) // prints 10s
const Minute Duration = 60000000000 Common durations. There is no definition for units of Day or larger to avoid confusion across daylight savings time zone transitions. To count the number of units in a Duration, divide: second := time.Second fmt.Print(int64(second/time.Millisecond)) // prints 1000 To convert an integer number of units to a Duration, multiply: seconds := 10 fmt.Print(time.Duration(seconds)*time.Second) // prints 10s
const Monday Weekday = 1
const Nanosecond Duration = 1 Common durations. There is no definition for units of Day or larger to avoid confusion across daylight savings time zone transitions. To count the number of units in a Duration, divide: second := time.Second fmt.Print(int64(second/time.Millisecond)) // prints 1000 To convert an integer number of units to a Duration, multiply: seconds := 10 fmt.Print(time.Duration(seconds)*time.Second) // prints 10s
func NewTicker(d Duration) *Ticker NewTicker returns a new Ticker containing a channel that will send the time with a period specified by the duration argument. It adjusts the intervals or drops ticks to make up for slow receivers. The duration d must be greater than zero; if not, NewTicker will panic. Stop the ticker to release associated resources.
func NewTimer(d Duration) *Timer NewTimer creates a new Timer that will send the current time on its channel after at least duration d.
const November Month = 11
func Now() Time Now returns the current local time.
const October Month = 10
func Parse(layout, value string) (Time, error) Parse parses a formatted string and returns the time value it represents. The layout defines the format by showing how the reference time, defined to be Mon Jan 2 15:04:05 -0700 MST 2006 would be interpreted if it were the value; it serves as an example of the input format. The same interpretation will then be made to the input string. Predefined layouts ANSIC, UnixDate, RFC3339 and others describe standard and convenient representations of the reference time. For more information about the formats and the definition of the reference time, see the documentation for ANSIC and the other constants defined by this package. Also, the executable example for Time.Format demonstrates the working of the layout string in detail and is a good reference. Elements omitted from the value are assumed to be zero or, when zero is impossible, one, so parsing "3:04pm" returns the time corresponding to Jan 1, year 0, 15:04:00 UTC (note that because the year is 0, this time is before the zero Time). Years must be in the range 0000..9999. The day of the week is checked for syntax but it is otherwise ignored. For layouts specifying the two-digit year 06, a value NN >= 69 will be treated as 19NN and a value NN < 69 will be treated as 20NN. In the absence of a time zone indicator, Parse returns a time in UTC. When parsing a time with a zone offset like -0700, if the offset corresponds to a time zone used by the current location (Local), then Parse uses that location and zone in the returned time. Otherwise it records the time as being in a fabricated location with time fixed at the given zone offset. When parsing a time with a zone abbreviation like MST, if the zone abbreviation has a defined offset in the current location, then that offset is used. The zone abbreviation "UTC" is recognized as UTC regardless of location. If the zone abbreviation is unknown, Parse records the time as being in a fabricated location with the given zone abbreviation and a zero offset. This choice means that such a time can be parsed and reformatted with the same layout losslessly, but the exact instant used in the representation will differ by the actual zone offset. To avoid such problems, prefer time layouts that use a numeric zone offset, or use ParseInLocation.
func ParseDuration(s string) (Duration, error) 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".
func ParseInLocation(layout, value string, loc *Location) (Time, error) 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.
const RFC1123 = "Mon, 02 Jan 2006 15:04:05 MST" These are predefined layouts for use in Time.Format and time.Parse. The reference time used in the layouts is the specific time: Mon Jan 2 15:04:05 MST 2006 which is Unix time 1136239445. Since MST is GMT-0700, the reference time can be thought of as 01/02 03:04:05PM '06 -0700 To define your own format, write down what the reference time would look like formatted your way; see the values of constants like ANSIC, StampMicro or Kitchen for examples. The model is to demonstrate what the reference time looks like so that the Format and Parse methods can apply the same transformation to a general time value. Some valid layouts are invalid time values for time.Parse, due to formats such as _ for space padding and Z for zone information. Within the format string, an underscore _ represents a space that may be replaced by a digit if the following number (a day) has two digits; for compatibility with fixed-width Unix time formats. A decimal point followed by one or more zeros represents a fractional second, printed to the given number of decimal places. A decimal point followed by one or more nines represents a fractional second, printed to the given number of decimal places, with trailing zeros removed. When parsing (only), the input may contain a fractional second field immediately after the seconds field, even if the layout does not signify its presence. In that case a decimal point followed by a maximal series of digits is parsed as a fractional second. Numeric time zone offsets format as follows: -0700 ±hhmm -07:00 ±hh:mm -07 ±hh Replacing the sign in the format with a Z triggers the ISO 8601 behavior of printing Z instead of an offset for the UTC zone. Thus: Z0700 Z or ±hhmm Z07:00 Z or ±hh:mm Z07 Z or ±hh The recognized day of week formats are "Mon" and "Monday". The recognized month formats are "Jan" and "January". The formats 2, _2, and 02 are unpadded, space-padded, and zero-padded day of month. The formats __2 and 002 are space-padded and zero-padded three-character day of year; there is no unpadded day of year format. Text in the format string that is not recognized as part of the reference time is echoed verbatim during Format and expected to appear verbatim in the input to Parse. The executable example for Time.Format demonstrates the working of the layout string in detail and is a good reference. Note that the RFC822, RFC850, and RFC1123 formats should be applied only to local times. Applying them to UTC times will use "UTC" as the time zone abbreviation, while strictly speaking those RFCs require the use of "GMT" in that case. In general RFC1123Z should be used instead of RFC1123 for servers that insist on that format, and RFC3339 should be preferred for new protocols. RFC3339, RFC822, RFC822Z, RFC1123, and RFC1123Z are useful for formatting; when used with time.Parse they do not accept all the time formats permitted by the RFCs and they do accept time formats not formally defined. The RFC3339Nano format removes trailing zeros from the seconds field and thus may not sort correctly once formatted.
const RFC1123Z = "Mon, 02 Jan 2006 15:04:05 -0700" // RFC1123 with numeric zone These are predefined layouts for use in Time.Format and time.Parse. The reference time used in the layouts is the specific time: Mon Jan 2 15:04:05 MST 2006 which is Unix time 1136239445. Since MST is GMT-0700, the reference time can be thought of as 01/02 03:04:05PM '06 -0700 To define your own format, write down what the reference time would look like formatted your way; see the values of constants like ANSIC, StampMicro or Kitchen for examples. The model is to demonstrate what the reference time looks like so that the Format and Parse methods can apply the same transformation to a general time value. Some valid layouts are invalid time values for time.Parse, due to formats such as _ for space padding and Z for zone information. Within the format string, an underscore _ represents a space that may be replaced by a digit if the following number (a day) has two digits; for compatibility with fixed-width Unix time formats. A decimal point followed by one or more zeros represents a fractional second, printed to the given number of decimal places. A decimal point followed by one or more nines represents a fractional second, printed to the given number of decimal places, with trailing zeros removed. When parsing (only), the input may contain a fractional second field immediately after the seconds field, even if the layout does not signify its presence. In that case a decimal point followed by a maximal series of digits is parsed as a fractional second. Numeric time zone offsets format as follows: -0700 ±hhmm -07:00 ±hh:mm -07 ±hh Replacing the sign in the format with a Z triggers the ISO 8601 behavior of printing Z instead of an offset for the UTC zone. Thus: Z0700 Z or ±hhmm Z07:00 Z or ±hh:mm Z07 Z or ±hh The recognized day of week formats are "Mon" and "Monday". The recognized month formats are "Jan" and "January". The formats 2, _2, and 02 are unpadded, space-padded, and zero-padded day of month. The formats __2 and 002 are space-padded and zero-padded three-character day of year; there is no unpadded day of year format. Text in the format string that is not recognized as part of the reference time is echoed verbatim during Format and expected to appear verbatim in the input to Parse. The executable example for Time.Format demonstrates the working of the layout string in detail and is a good reference. Note that the RFC822, RFC850, and RFC1123 formats should be applied only to local times. Applying them to UTC times will use "UTC" as the time zone abbreviation, while strictly speaking those RFCs require the use of "GMT" in that case. In general RFC1123Z should be used instead of RFC1123 for servers that insist on that format, and RFC3339 should be preferred for new protocols. RFC3339, RFC822, RFC822Z, RFC1123, and RFC1123Z are useful for formatting; when used with time.Parse they do not accept all the time formats permitted by the RFCs and they do accept time formats not formally defined. The RFC3339Nano format removes trailing zeros from the seconds field and thus may not sort correctly once formatted.
const RFC3339 = "2006-01-02T15:04:05Z07:00" These are predefined layouts for use in Time.Format and time.Parse. The reference time used in the layouts is the specific time: Mon Jan 2 15:04:05 MST 2006 which is Unix time 1136239445. Since MST is GMT-0700, the reference time can be thought of as 01/02 03:04:05PM '06 -0700 To define your own format, write down what the reference time would look like formatted your way; see the values of constants like ANSIC, StampMicro or Kitchen for examples. The model is to demonstrate what the reference time looks like so that the Format and Parse methods can apply the same transformation to a general time value. Some valid layouts are invalid time values for time.Parse, due to formats such as _ for space padding and Z for zone information. Within the format string, an underscore _ represents a space that may be replaced by a digit if the following number (a day) has two digits; for compatibility with fixed-width Unix time formats. A decimal point followed by one or more zeros represents a fractional second, printed to the given number of decimal places. A decimal point followed by one or more nines represents a fractional second, printed to the given number of decimal places, with trailing zeros removed. When parsing (only), the input may contain a fractional second field immediately after the seconds field, even if the layout does not signify its presence. In that case a decimal point followed by a maximal series of digits is parsed as a fractional second. Numeric time zone offsets format as follows: -0700 ±hhmm -07:00 ±hh:mm -07 ±hh Replacing the sign in the format with a Z triggers the ISO 8601 behavior of printing Z instead of an offset for the UTC zone. Thus: Z0700 Z or ±hhmm Z07:00 Z or ±hh:mm Z07 Z or ±hh The recognized day of week formats are "Mon" and "Monday". The recognized month formats are "Jan" and "January". The formats 2, _2, and 02 are unpadded, space-padded, and zero-padded day of month. The formats __2 and 002 are space-padded and zero-padded three-character day of year; there is no unpadded day of year format. Text in the format string that is not recognized as part of the reference time is echoed verbatim during Format and expected to appear verbatim in the input to Parse. The executable example for Time.Format demonstrates the working of the layout string in detail and is a good reference. Note that the RFC822, RFC850, and RFC1123 formats should be applied only to local times. Applying them to UTC times will use "UTC" as the time zone abbreviation, while strictly speaking those RFCs require the use of "GMT" in that case. In general RFC1123Z should be used instead of RFC1123 for servers that insist on that format, and RFC3339 should be preferred for new protocols. RFC3339, RFC822, RFC822Z, RFC1123, and RFC1123Z are useful for formatting; when used with time.Parse they do not accept all the time formats permitted by the RFCs and they do accept time formats not formally defined. The RFC3339Nano format removes trailing zeros from the seconds field and thus may not sort correctly once formatted.
const RFC3339Nano = "2006-01-02T15:04:05.999999999Z07:00" These are predefined layouts for use in Time.Format and time.Parse. The reference time used in the layouts is the specific time: Mon Jan 2 15:04:05 MST 2006 which is Unix time 1136239445. Since MST is GMT-0700, the reference time can be thought of as 01/02 03:04:05PM '06 -0700 To define your own format, write down what the reference time would look like formatted your way; see the values of constants like ANSIC, StampMicro or Kitchen for examples. The model is to demonstrate what the reference time looks like so that the Format and Parse methods can apply the same transformation to a general time value. Some valid layouts are invalid time values for time.Parse, due to formats such as _ for space padding and Z for zone information. Within the format string, an underscore _ represents a space that may be replaced by a digit if the following number (a day) has two digits; for compatibility with fixed-width Unix time formats. A decimal point followed by one or more zeros represents a fractional second, printed to the given number of decimal places. A decimal point followed by one or more nines represents a fractional second, printed to the given number of decimal places, with trailing zeros removed. When parsing (only), the input may contain a fractional second field immediately after the seconds field, even if the layout does not signify its presence. In that case a decimal point followed by a maximal series of digits is parsed as a fractional second. Numeric time zone offsets format as follows: -0700 ±hhmm -07:00 ±hh:mm -07 ±hh Replacing the sign in the format with a Z triggers the ISO 8601 behavior of printing Z instead of an offset for the UTC zone. Thus: Z0700 Z or ±hhmm Z07:00 Z or ±hh:mm Z07 Z or ±hh The recognized day of week formats are "Mon" and "Monday". The recognized month formats are "Jan" and "January". The formats 2, _2, and 02 are unpadded, space-padded, and zero-padded day of month. The formats __2 and 002 are space-padded and zero-padded three-character day of year; there is no unpadded day of year format. Text in the format string that is not recognized as part of the reference time is echoed verbatim during Format and expected to appear verbatim in the input to Parse. The executable example for Time.Format demonstrates the working of the layout string in detail and is a good reference. Note that the RFC822, RFC850, and RFC1123 formats should be applied only to local times. Applying them to UTC times will use "UTC" as the time zone abbreviation, while strictly speaking those RFCs require the use of "GMT" in that case. In general RFC1123Z should be used instead of RFC1123 for servers that insist on that format, and RFC3339 should be preferred for new protocols. RFC3339, RFC822, RFC822Z, RFC1123, and RFC1123Z are useful for formatting; when used with time.Parse they do not accept all the time formats permitted by the RFCs and they do accept time formats not formally defined. The RFC3339Nano format removes trailing zeros from the seconds field and thus may not sort correctly once formatted.
const RFC822 = "02 Jan 06 15:04 MST" These are predefined layouts for use in Time.Format and time.Parse. The reference time used in the layouts is the specific time: Mon Jan 2 15:04:05 MST 2006 which is Unix time 1136239445. Since MST is GMT-0700, the reference time can be thought of as 01/02 03:04:05PM '06 -0700 To define your own format, write down what the reference time would look like formatted your way; see the values of constants like ANSIC, StampMicro or Kitchen for examples. The model is to demonstrate what the reference time looks like so that the Format and Parse methods can apply the same transformation to a general time value. Some valid layouts are invalid time values for time.Parse, due to formats such as _ for space padding and Z for zone information. Within the format string, an underscore _ represents a space that may be replaced by a digit if the following number (a day) has two digits; for compatibility with fixed-width Unix time formats. A decimal point followed by one or more zeros represents a fractional second, printed to the given number of decimal places. A decimal point followed by one or more nines represents a fractional second, printed to the given number of decimal places, with trailing zeros removed. When parsing (only), the input may contain a fractional second field immediately after the seconds field, even if the layout does not signify its presence. In that case a decimal point followed by a maximal series of digits is parsed as a fractional second. Numeric time zone offsets format as follows: -0700 ±hhmm -07:00 ±hh:mm -07 ±hh Replacing the sign in the format with a Z triggers the ISO 8601 behavior of printing Z instead of an offset for the UTC zone. Thus: Z0700 Z or ±hhmm Z07:00 Z or ±hh:mm Z07 Z or ±hh The recognized day of week formats are "Mon" and "Monday". The recognized month formats are "Jan" and "January". The formats 2, _2, and 02 are unpadded, space-padded, and zero-padded day of month. The formats __2 and 002 are space-padded and zero-padded three-character day of year; there is no unpadded day of year format. Text in the format string that is not recognized as part of the reference time is echoed verbatim during Format and expected to appear verbatim in the input to Parse. The executable example for Time.Format demonstrates the working of the layout string in detail and is a good reference. Note that the RFC822, RFC850, and RFC1123 formats should be applied only to local times. Applying them to UTC times will use "UTC" as the time zone abbreviation, while strictly speaking those RFCs require the use of "GMT" in that case. In general RFC1123Z should be used instead of RFC1123 for servers that insist on that format, and RFC3339 should be preferred for new protocols. RFC3339, RFC822, RFC822Z, RFC1123, and RFC1123Z are useful for formatting; when used with time.Parse they do not accept all the time formats permitted by the RFCs and they do accept time formats not formally defined. The RFC3339Nano format removes trailing zeros from the seconds field and thus may not sort correctly once formatted.
const RFC822Z = "02 Jan 06 15:04 -0700" // RFC822 with numeric zone These are predefined layouts for use in Time.Format and time.Parse. The reference time used in the layouts is the specific time: Mon Jan 2 15:04:05 MST 2006 which is Unix time 1136239445. Since MST is GMT-0700, the reference time can be thought of as 01/02 03:04:05PM '06 -0700 To define your own format, write down what the reference time would look like formatted your way; see the values of constants like ANSIC, StampMicro or Kitchen for examples. The model is to demonstrate what the reference time looks like so that the Format and Parse methods can apply the same transformation to a general time value. Some valid layouts are invalid time values for time.Parse, due to formats such as _ for space padding and Z for zone information. Within the format string, an underscore _ represents a space that may be replaced by a digit if the following number (a day) has two digits; for compatibility with fixed-width Unix time formats. A decimal point followed by one or more zeros represents a fractional second, printed to the given number of decimal places. A decimal point followed by one or more nines represents a fractional second, printed to the given number of decimal places, with trailing zeros removed. When parsing (only), the input may contain a fractional second field immediately after the seconds field, even if the layout does not signify its presence. In that case a decimal point followed by a maximal series of digits is parsed as a fractional second. Numeric time zone offsets format as follows: -0700 ±hhmm -07:00 ±hh:mm -07 ±hh Replacing the sign in the format with a Z triggers the ISO 8601 behavior of printing Z instead of an offset for the UTC zone. Thus: Z0700 Z or ±hhmm Z07:00 Z or ±hh:mm Z07 Z or ±hh The recognized day of week formats are "Mon" and "Monday". The recognized month formats are "Jan" and "January". The formats 2, _2, and 02 are unpadded, space-padded, and zero-padded day of month. The formats __2 and 002 are space-padded and zero-padded three-character day of year; there is no unpadded day of year format. Text in the format string that is not recognized as part of the reference time is echoed verbatim during Format and expected to appear verbatim in the input to Parse. The executable example for Time.Format demonstrates the working of the layout string in detail and is a good reference. Note that the RFC822, RFC850, and RFC1123 formats should be applied only to local times. Applying them to UTC times will use "UTC" as the time zone abbreviation, while strictly speaking those RFCs require the use of "GMT" in that case. In general RFC1123Z should be used instead of RFC1123 for servers that insist on that format, and RFC3339 should be preferred for new protocols. RFC3339, RFC822, RFC822Z, RFC1123, and RFC1123Z are useful for formatting; when used with time.Parse they do not accept all the time formats permitted by the RFCs and they do accept time formats not formally defined. The RFC3339Nano format removes trailing zeros from the seconds field and thus may not sort correctly once formatted.
const RFC850 = "Monday, 02-Jan-06 15:04:05 MST" These are predefined layouts for use in Time.Format and time.Parse. The reference time used in the layouts is the specific time: Mon Jan 2 15:04:05 MST 2006 which is Unix time 1136239445. Since MST is GMT-0700, the reference time can be thought of as 01/02 03:04:05PM '06 -0700 To define your own format, write down what the reference time would look like formatted your way; see the values of constants like ANSIC, StampMicro or Kitchen for examples. The model is to demonstrate what the reference time looks like so that the Format and Parse methods can apply the same transformation to a general time value. Some valid layouts are invalid time values for time.Parse, due to formats such as _ for space padding and Z for zone information. Within the format string, an underscore _ represents a space that may be replaced by a digit if the following number (a day) has two digits; for compatibility with fixed-width Unix time formats. A decimal point followed by one or more zeros represents a fractional second, printed to the given number of decimal places. A decimal point followed by one or more nines represents a fractional second, printed to the given number of decimal places, with trailing zeros removed. When parsing (only), the input may contain a fractional second field immediately after the seconds field, even if the layout does not signify its presence. In that case a decimal point followed by a maximal series of digits is parsed as a fractional second. Numeric time zone offsets format as follows: -0700 ±hhmm -07:00 ±hh:mm -07 ±hh Replacing the sign in the format with a Z triggers the ISO 8601 behavior of printing Z instead of an offset for the UTC zone. Thus: Z0700 Z or ±hhmm Z07:00 Z or ±hh:mm Z07 Z or ±hh The recognized day of week formats are "Mon" and "Monday". The recognized month formats are "Jan" and "January". The formats 2, _2, and 02 are unpadded, space-padded, and zero-padded day of month. The formats __2 and 002 are space-padded and zero-padded three-character day of year; there is no unpadded day of year format. Text in the format string that is not recognized as part of the reference time is echoed verbatim during Format and expected to appear verbatim in the input to Parse. The executable example for Time.Format demonstrates the working of the layout string in detail and is a good reference. Note that the RFC822, RFC850, and RFC1123 formats should be applied only to local times. Applying them to UTC times will use "UTC" as the time zone abbreviation, while strictly speaking those RFCs require the use of "GMT" in that case. In general RFC1123Z should be used instead of RFC1123 for servers that insist on that format, and RFC3339 should be preferred for new protocols. RFC3339, RFC822, RFC822Z, RFC1123, and RFC1123Z are useful for formatting; when used with time.Parse they do not accept all the time formats permitted by the RFCs and they do accept time formats not formally defined. The RFC3339Nano format removes trailing zeros from the seconds field and thus may not sort correctly once formatted.
const RubyDate = "Mon Jan 02 15:04:05 -0700 2006" These are predefined layouts for use in Time.Format and time.Parse. The reference time used in the layouts is the specific time: Mon Jan 2 15:04:05 MST 2006 which is Unix time 1136239445. Since MST is GMT-0700, the reference time can be thought of as 01/02 03:04:05PM '06 -0700 To define your own format, write down what the reference time would look like formatted your way; see the values of constants like ANSIC, StampMicro or Kitchen for examples. The model is to demonstrate what the reference time looks like so that the Format and Parse methods can apply the same transformation to a general time value. Some valid layouts are invalid time values for time.Parse, due to formats such as _ for space padding and Z for zone information. Within the format string, an underscore _ represents a space that may be replaced by a digit if the following number (a day) has two digits; for compatibility with fixed-width Unix time formats. A decimal point followed by one or more zeros represents a fractional second, printed to the given number of decimal places. A decimal point followed by one or more nines represents a fractional second, printed to the given number of decimal places, with trailing zeros removed. When parsing (only), the input may contain a fractional second field immediately after the seconds field, even if the layout does not signify its presence. In that case a decimal point followed by a maximal series of digits is parsed as a fractional second. Numeric time zone offsets format as follows: -0700 ±hhmm -07:00 ±hh:mm -07 ±hh Replacing the sign in the format with a Z triggers the ISO 8601 behavior of printing Z instead of an offset for the UTC zone. Thus: Z0700 Z or ±hhmm Z07:00 Z or ±hh:mm Z07 Z or ±hh The recognized day of week formats are "Mon" and "Monday". The recognized month formats are "Jan" and "January". The formats 2, _2, and 02 are unpadded, space-padded, and zero-padded day of month. The formats __2 and 002 are space-padded and zero-padded three-character day of year; there is no unpadded day of year format. Text in the format string that is not recognized as part of the reference time is echoed verbatim during Format and expected to appear verbatim in the input to Parse. The executable example for Time.Format demonstrates the working of the layout string in detail and is a good reference. Note that the RFC822, RFC850, and RFC1123 formats should be applied only to local times. Applying them to UTC times will use "UTC" as the time zone abbreviation, while strictly speaking those RFCs require the use of "GMT" in that case. In general RFC1123Z should be used instead of RFC1123 for servers that insist on that format, and RFC3339 should be preferred for new protocols. RFC3339, RFC822, RFC822Z, RFC1123, and RFC1123Z are useful for formatting; when used with time.Parse they do not accept all the time formats permitted by the RFCs and they do accept time formats not formally defined. The RFC3339Nano format removes trailing zeros from the seconds field and thus may not sort correctly once formatted.
const Saturday Weekday = 6
const Second Duration = 1000000000 Common durations. There is no definition for units of Day or larger to avoid confusion across daylight savings time zone transitions. To count the number of units in a Duration, divide: second := time.Second fmt.Print(int64(second/time.Millisecond)) // prints 1000 To convert an integer number of units to a Duration, multiply: seconds := 10 fmt.Print(time.Duration(seconds)*time.Second) // prints 10s
const September Month = 9
func Since(t Time) Duration Since returns the time elapsed since t. It is shorthand for time.Now().Sub(t).
func Sleep(d Duration) Sleep pauses the current goroutine for at least the duration d. A negative or zero duration causes Sleep to return immediately.
const Stamp = "Jan _2 15:04:05" Handy time stamps.
const StampMicro = "Jan _2 15:04:05.000000" These are predefined layouts for use in Time.Format and time.Parse. The reference time used in the layouts is the specific time: Mon Jan 2 15:04:05 MST 2006 which is Unix time 1136239445. Since MST is GMT-0700, the reference time can be thought of as 01/02 03:04:05PM '06 -0700 To define your own format, write down what the reference time would look like formatted your way; see the values of constants like ANSIC, StampMicro or Kitchen for examples. The model is to demonstrate what the reference time looks like so that the Format and Parse methods can apply the same transformation to a general time value. Some valid layouts are invalid time values for time.Parse, due to formats such as _ for space padding and Z for zone information. Within the format string, an underscore _ represents a space that may be replaced by a digit if the following number (a day) has two digits; for compatibility with fixed-width Unix time formats. A decimal point followed by one or more zeros represents a fractional second, printed to the given number of decimal places. A decimal point followed by one or more nines represents a fractional second, printed to the given number of decimal places, with trailing zeros removed. When parsing (only), the input may contain a fractional second field immediately after the seconds field, even if the layout does not signify its presence. In that case a decimal point followed by a maximal series of digits is parsed as a fractional second. Numeric time zone offsets format as follows: -0700 ±hhmm -07:00 ±hh:mm -07 ±hh Replacing the sign in the format with a Z triggers the ISO 8601 behavior of printing Z instead of an offset for the UTC zone. Thus: Z0700 Z or ±hhmm Z07:00 Z or ±hh:mm Z07 Z or ±hh The recognized day of week formats are "Mon" and "Monday". The recognized month formats are "Jan" and "January". The formats 2, _2, and 02 are unpadded, space-padded, and zero-padded day of month. The formats __2 and 002 are space-padded and zero-padded three-character day of year; there is no unpadded day of year format. Text in the format string that is not recognized as part of the reference time is echoed verbatim during Format and expected to appear verbatim in the input to Parse. The executable example for Time.Format demonstrates the working of the layout string in detail and is a good reference. Note that the RFC822, RFC850, and RFC1123 formats should be applied only to local times. Applying them to UTC times will use "UTC" as the time zone abbreviation, while strictly speaking those RFCs require the use of "GMT" in that case. In general RFC1123Z should be used instead of RFC1123 for servers that insist on that format, and RFC3339 should be preferred for new protocols. RFC3339, RFC822, RFC822Z, RFC1123, and RFC1123Z are useful for formatting; when used with time.Parse they do not accept all the time formats permitted by the RFCs and they do accept time formats not formally defined. The RFC3339Nano format removes trailing zeros from the seconds field and thus may not sort correctly once formatted.
const StampMilli = "Jan _2 15:04:05.000" These are predefined layouts for use in Time.Format and time.Parse. The reference time used in the layouts is the specific time: Mon Jan 2 15:04:05 MST 2006 which is Unix time 1136239445. Since MST is GMT-0700, the reference time can be thought of as 01/02 03:04:05PM '06 -0700 To define your own format, write down what the reference time would look like formatted your way; see the values of constants like ANSIC, StampMicro or Kitchen for examples. The model is to demonstrate what the reference time looks like so that the Format and Parse methods can apply the same transformation to a general time value. Some valid layouts are invalid time values for time.Parse, due to formats such as _ for space padding and Z for zone information. Within the format string, an underscore _ represents a space that may be replaced by a digit if the following number (a day) has two digits; for compatibility with fixed-width Unix time formats. A decimal point followed by one or more zeros represents a fractional second, printed to the given number of decimal places. A decimal point followed by one or more nines represents a fractional second, printed to the given number of decimal places, with trailing zeros removed. When parsing (only), the input may contain a fractional second field immediately after the seconds field, even if the layout does not signify its presence. In that case a decimal point followed by a maximal series of digits is parsed as a fractional second. Numeric time zone offsets format as follows: -0700 ±hhmm -07:00 ±hh:mm -07 ±hh Replacing the sign in the format with a Z triggers the ISO 8601 behavior of printing Z instead of an offset for the UTC zone. Thus: Z0700 Z or ±hhmm Z07:00 Z or ±hh:mm Z07 Z or ±hh The recognized day of week formats are "Mon" and "Monday". The recognized month formats are "Jan" and "January". The formats 2, _2, and 02 are unpadded, space-padded, and zero-padded day of month. The formats __2 and 002 are space-padded and zero-padded three-character day of year; there is no unpadded day of year format. Text in the format string that is not recognized as part of the reference time is echoed verbatim during Format and expected to appear verbatim in the input to Parse. The executable example for Time.Format demonstrates the working of the layout string in detail and is a good reference. Note that the RFC822, RFC850, and RFC1123 formats should be applied only to local times. Applying them to UTC times will use "UTC" as the time zone abbreviation, while strictly speaking those RFCs require the use of "GMT" in that case. In general RFC1123Z should be used instead of RFC1123 for servers that insist on that format, and RFC3339 should be preferred for new protocols. RFC3339, RFC822, RFC822Z, RFC1123, and RFC1123Z are useful for formatting; when used with time.Parse they do not accept all the time formats permitted by the RFCs and they do accept time formats not formally defined. The RFC3339Nano format removes trailing zeros from the seconds field and thus may not sort correctly once formatted.
const StampNano = "Jan _2 15:04:05.000000000" These are predefined layouts for use in Time.Format and time.Parse. The reference time used in the layouts is the specific time: Mon Jan 2 15:04:05 MST 2006 which is Unix time 1136239445. Since MST is GMT-0700, the reference time can be thought of as 01/02 03:04:05PM '06 -0700 To define your own format, write down what the reference time would look like formatted your way; see the values of constants like ANSIC, StampMicro or Kitchen for examples. The model is to demonstrate what the reference time looks like so that the Format and Parse methods can apply the same transformation to a general time value. Some valid layouts are invalid time values for time.Parse, due to formats such as _ for space padding and Z for zone information. Within the format string, an underscore _ represents a space that may be replaced by a digit if the following number (a day) has two digits; for compatibility with fixed-width Unix time formats. A decimal point followed by one or more zeros represents a fractional second, printed to the given number of decimal places. A decimal point followed by one or more nines represents a fractional second, printed to the given number of decimal places, with trailing zeros removed. When parsing (only), the input may contain a fractional second field immediately after the seconds field, even if the layout does not signify its presence. In that case a decimal point followed by a maximal series of digits is parsed as a fractional second. Numeric time zone offsets format as follows: -0700 ±hhmm -07:00 ±hh:mm -07 ±hh Replacing the sign in the format with a Z triggers the ISO 8601 behavior of printing Z instead of an offset for the UTC zone. Thus: Z0700 Z or ±hhmm Z07:00 Z or ±hh:mm Z07 Z or ±hh The recognized day of week formats are "Mon" and "Monday". The recognized month formats are "Jan" and "January". The formats 2, _2, and 02 are unpadded, space-padded, and zero-padded day of month. The formats __2 and 002 are space-padded and zero-padded three-character day of year; there is no unpadded day of year format. Text in the format string that is not recognized as part of the reference time is echoed verbatim during Format and expected to appear verbatim in the input to Parse. The executable example for Time.Format demonstrates the working of the layout string in detail and is a good reference. Note that the RFC822, RFC850, and RFC1123 formats should be applied only to local times. Applying them to UTC times will use "UTC" as the time zone abbreviation, while strictly speaking those RFCs require the use of "GMT" in that case. In general RFC1123Z should be used instead of RFC1123 for servers that insist on that format, and RFC3339 should be preferred for new protocols. RFC3339, RFC822, RFC822Z, RFC1123, and RFC1123Z are useful for formatting; when used with time.Parse they do not accept all the time formats permitted by the RFCs and they do accept time formats not formally defined. The RFC3339Nano format removes trailing zeros from the seconds field and thus may not sort correctly once formatted.
const Sunday Weekday = 0
const Thursday Weekday = 4
func Tick(d Duration) <-chan Time Tick is a convenience wrapper for NewTicker providing access to the ticking channel only. While Tick is useful for clients that have no need to shut down the Ticker, be aware that without a way to shut it down the underlying Ticker cannot be recovered by the garbage collector; it "leaks". Unlike NewTicker, Tick will return nil if d <= 0.
const Tuesday Weekday = 2
func Unix(sec int64, nsec int64) Time 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).
const UnixDate = "Mon Jan _2 15:04:05 MST 2006" These are predefined layouts for use in Time.Format and time.Parse. The reference time used in the layouts is the specific time: Mon Jan 2 15:04:05 MST 2006 which is Unix time 1136239445. Since MST is GMT-0700, the reference time can be thought of as 01/02 03:04:05PM '06 -0700 To define your own format, write down what the reference time would look like formatted your way; see the values of constants like ANSIC, StampMicro or Kitchen for examples. The model is to demonstrate what the reference time looks like so that the Format and Parse methods can apply the same transformation to a general time value. Some valid layouts are invalid time values for time.Parse, due to formats such as _ for space padding and Z for zone information. Within the format string, an underscore _ represents a space that may be replaced by a digit if the following number (a day) has two digits; for compatibility with fixed-width Unix time formats. A decimal point followed by one or more zeros represents a fractional second, printed to the given number of decimal places. A decimal point followed by one or more nines represents a fractional second, printed to the given number of decimal places, with trailing zeros removed. When parsing (only), the input may contain a fractional second field immediately after the seconds field, even if the layout does not signify its presence. In that case a decimal point followed by a maximal series of digits is parsed as a fractional second. Numeric time zone offsets format as follows: -0700 ±hhmm -07:00 ±hh:mm -07 ±hh Replacing the sign in the format with a Z triggers the ISO 8601 behavior of printing Z instead of an offset for the UTC zone. Thus: Z0700 Z or ±hhmm Z07:00 Z or ±hh:mm Z07 Z or ±hh The recognized day of week formats are "Mon" and "Monday". The recognized month formats are "Jan" and "January". The formats 2, _2, and 02 are unpadded, space-padded, and zero-padded day of month. The formats __2 and 002 are space-padded and zero-padded three-character day of year; there is no unpadded day of year format. Text in the format string that is not recognized as part of the reference time is echoed verbatim during Format and expected to appear verbatim in the input to Parse. The executable example for Time.Format demonstrates the working of the layout string in detail and is a good reference. Note that the RFC822, RFC850, and RFC1123 formats should be applied only to local times. Applying them to UTC times will use "UTC" as the time zone abbreviation, while strictly speaking those RFCs require the use of "GMT" in that case. In general RFC1123Z should be used instead of RFC1123 for servers that insist on that format, and RFC3339 should be preferred for new protocols. RFC3339, RFC822, RFC822Z, RFC1123, and RFC1123Z are useful for formatting; when used with time.Parse they do not accept all the time formats permitted by the RFCs and they do accept time formats not formally defined. The RFC3339Nano format removes trailing zeros from the seconds field and thus may not sort correctly once formatted.
func Until(t Time) Duration Until returns the duration until t. It is shorthand for t.Sub(time.Now()).
var UTC *Location UTC represents Universal Coordinated Time (UTC).
const Wednesday Weekday = 3