These are predefined layouts for use in Time.Format and time.Parse.
The reference time used in these layouts is the specific time stamp:
01/02 03:04:05PM '06 -0700
(January 2, 15:04:05, 2006, in time zone seven hours west of GMT).
That value is recorded as the constant named Layout, listed below. As a
Unix time, this is 1136239445. Since MST is GMT-0700, the reference would be
printed by the Unix date command as:
Mon Jan 2 15:04:05 MST 2006
It is a regrettable historic error that the date uses the American
convention of putting the numerical month before the day.
The 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. When using the RFC1123 or RFC1123Z formats for parsing,
note that these formats define a leading zero for the day-in-month portion,
which is not strictly allowed by RFC 1123. This will result in an error
when parsing date strings that occur in the first 9 days of a given month.
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.
Most programs can use one of the defined constants as the layout passed
to Format or Parse. The rest of this comment can be ignored unless you are
creating a custom layout string.
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.
Here is a summary of the components of a layout string. Each element shows
by example the formatting of an element of the reference time. Only these
values are recognized. Text in the layout 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.
Year: "2006" "06"
Month: "Jan" "January" "01" "1"
Day of the week: "Mon" "Monday"
Day of the month: "2" "_2" "02"
Day of the year: "__2" "002"
Hour: "15" "3" "03" (PM or AM)
Minute: "4" "04"
Second: "5" "05"
AM/PM mark: "PM"
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
"Z070000" Z or ±hhmmss
"Z07:00:00" Z or ±hh:mm:ss
Within the format string, the underscores in "_2" and "__2" represent spaces
that may be replaced by digits if the following number has multiple digits,
for compatibility with fixed-width Unix time formats. A leading zero
represents a zero-padded value.
The formats __2 and 002 are space-padded and zero-padded three-character day
of year; there is no unpadded day of year format.
A comma or decimal point followed by one or more zeros represents a
fractional second, printed to the given number of decimal places. A comma or
decimal point followed by one or more nines represents a fractional second,
printed to the given number of decimal places, with trailing zeros removed.
For example "15:04:05,000" or "15:04:05.000" formats or parses with
millisecond precision.
Some valid layouts are invalid time values for time.Parse, due to formats
such as _ for space padding and Z for zone information.
These are predefined layouts for use in Time.Format and time.Parse. The reference time used in these layouts is the specific time stamp:
(January 2, 15:04:05, 2006, in time zone seven hours west of GMT). That value is recorded as the constant named Layout, listed below. As a Unix time, this is 1136239445. Since MST is GMT-0700, the reference would be printed by the Unix date command as:
It is a regrettable historic error that the date uses the American convention of putting the numerical month before the day.
The 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. When using the RFC1123 or RFC1123Z formats for parsing, note that these formats define a leading zero for the day-in-month portion, which is not strictly allowed by RFC 1123. This will result in an error when parsing date strings that occur in the first 9 days of a given month. 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.
Most programs can use one of the defined constants as the layout passed to Format or Parse. The rest of this comment can be ignored unless you are creating a custom layout string.
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.
Here is a summary of the components of a layout string. Each element shows by example the formatting of an element of the reference time. Only these values are recognized. Text in the layout 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.
Numeric time zone offsets format as follows:
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:
Within the format string, the underscores in "_2" and "__2" represent spaces that may be replaced by digits if the following number has multiple digits, for compatibility with fixed-width Unix time formats. A leading zero represents a zero-padded value.
The formats __2 and 002 are space-padded and zero-padded three-character day of year; there is no unpadded day of year format.
A comma or decimal point followed by one or more zeros represents a fractional second, printed to the given number of decimal places. A comma or decimal point followed by one or more nines represents a fractional second, printed to the given number of decimal places, with trailing zeros removed. For example "15:04:05,000" or "15:04:05.000" formats or parses with millisecond precision.
Some valid layouts are invalid time values for time.Parse, due to formats such as _ for space padding and Z for zone information.