You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: format.go
+86-36
Original file line number
Diff line number
Diff line change
@@ -9,39 +9,52 @@ import (
9
9
// These are predefined layouts used for the parsing and formatting of dates, times and date-times.
10
10
// Additional layouts can be composed using the specifiers detailed below:
11
11
//
12
-
// %Y: The ISO 8601 year as a decimal number, padded to 4 digits with leading 0s.
13
-
// %EY: The year in the era as a decimal number, padded to 4 digits with leading 0s.
14
-
// %y: The ISO 8601 year without a century as a decimal number, padded to 2 digits with a leading 0, in the range 00 to 99. See note (1).
15
-
// %Ey: The year in the era without a century as a decimal number, padded to 2 digits with a leading 0, in the range 00 to 99. See note (1).
16
-
// %EC: The name of the era, either "CE" (for Common Era) "BCE" (for Before the Common Era).
17
-
// %j: The day of the year as a decimal number, padded to 3 digits with leading 0s, in the range 001 to 366. See note (2).
18
-
// %m: The month as a decimal number, padded to 2 digits with a leading 0, in the range 01 to 12.
19
-
// %B: The full month name, e.g. January, February, etc.
20
-
// %b: The abbreviated month name, e.g. Jan, Feb, etc.
21
-
// %d: The day of the month as a decimal number, padded to 2 digits with a leading 0, in the range 01 to 31.
12
+
// - %Y: The ISO 8601 year as a decimal number, padded to 4 digits with leading 0s.
13
+
// - %EY: The year in the era as a decimal number, padded to 4 digits with leading 0s.
14
+
// - %y: The ISO 8601 year without a century as a decimal number, padded to 2 digits with a leading 0, in the range 00 to 99. See note (1).
15
+
// - %Ey: The year in the era without a century as a decimal number, padded to 2 digits with a leading 0, in the range 00 to 99. See notes (1) and (9).
16
+
// - %C: The century as a decimal number, padded to 2 digits with a leading 0, e.g. 19 for 1980. See note (9).
17
+
// - %EC: The name of the era, either "CE" (for Common Era) "BCE" (for Before the Common Era).
18
+
// - %j: The day of the year as a decimal number, padded to 3 digits with leading 0s, in the range 001 to 366. See note (2).
19
+
// - %m: The month as a decimal number, padded to 2 digits with a leading 0, in the range 01 to 12.
20
+
// - %B: The full month name, e.g. January, February, etc.
21
+
// - %b: The abbreviated month name, e.g. Jan, Feb, etc.
22
+
// - %d: The day of the month as a decimal number, padded to 2 digits with a leading 0, in the range 01 to 31.
22
23
//
23
-
// %u: The day of the week as a decimal number, e.g. 1 for Monday, 2 for Tuesday, etc. See note (3).
24
-
// %A: The full name of the day of the week, e.g. Monday, Tuesday, etc. See note (3).
25
-
// %a: The abbreviated name of the day of the week, e.g. Mon, Tue, etc. See note (3).
24
+
// Days of week:
26
25
//
27
-
// %G: The ISO 8601 week-based year, padded to 4 digits with leading 0s. This may differ by ±1 to the actual calendar year. See note (2).
28
-
// %V: The ISO week number, padded to 2 digits with a leading 0, in the range 01 to 53. See note (2).
26
+
// - %u: The day of the week as a decimal number, e.g. 1 for Monday, 2 for Tuesday, etc. See note (3).
27
+
// - %A: The full name of the day of the week, e.g. Monday, Tuesday, etc. See note (3).
28
+
// - %a: The abbreviated name of the day of the week, e.g. Mon, Tue, etc. See note (3).
29
29
//
30
-
// %P: Either "am" or "pm", where noon is "pm" and midnight is "am".
31
-
// %p: Either "AM" or "PM", where noon is "PM" and midnight is "AM".
32
-
// %I: The hour of the day using the 12-hour clock as a decimal number, padded to 2 digits with a leading 0, in the range 01 to 12. See note (4).
30
+
// Week numbers:
33
31
//
34
-
// %H: The hour of the day using the 24-hour clock as a decimal number, padded to 2 digits with a leading 0, in the range 00 to 23. See note (5).
35
-
// %M: The minute as a decimal number, padded to 2 digits with a leading 0, in the range 00 to 59.
36
-
// %S: The second as a decimal number, padded to 2 digits with a leading 0, in the range 00 to 59.
32
+
// - %G: The ISO 8601 week-based year, padded to 4 digits with leading 0s. This may differ by ±1 to the actual calendar year. See note (2).
33
+
// - %V: The ISO week number, padded to 2 digits with a leading 0, in the range 01 to 53. See note (2).
37
34
//
38
-
// %f: Equivalent to %6f.
39
-
// %3f: The millisecond offset within the represented second, rounded either up or down and padded to 3 digits with leading 0s.
40
-
// %6f: The microsecond offset within the represented second, rounded either up or down and padded to 6 digits with leading 0s.
41
-
// %9f: The nanosecond offset within the represented second, padded to 9 digits with leading 0s.
35
+
// Times of day:
42
36
//
43
-
// %z: The UTC offset in the format ±HHMM, preceded always by the sign ('+' or '-'), and padded to 4 digits with leading zeros. See notes (6), (7), and (8).
44
-
// %Ez: Equivalent to %z, except that an offset of +0000 is formatted at 'Z', and other offsets as ±HH:MM. See notes (6) and (7).
37
+
// - %P: Either "am" or "pm", where noon is "pm" and midnight is "am".
38
+
// - %p: Either "AM" or "PM", where noon is "PM" and midnight is "AM".
39
+
// - %I: The hour of the day using the 12-hour clock as a decimal number, padded to 2 digits with a leading 0, in the range 01 to 12. See note (4).
40
+
//
41
+
// Time components:
42
+
//
43
+
// - %H: The hour of the day using the 24-hour clock as a decimal number, padded to 2 digits with a leading 0, in the range 00 to 23. See note (5).
44
+
// - %M: The minute as a decimal number, padded to 2 digits with a leading 0, in the range 00 to 59.
45
+
// - %S: The second as a decimal number, padded to 2 digits with a leading 0, in the range 00 to 59.
46
+
//
47
+
// Millisecond precisions:
48
+
//
49
+
// - %f: Equivalent to %6f.
50
+
// - %3f: The millisecond offset within the represented second, rounded either up or down and padded to 3 digits with leading 0s.
51
+
// - %6f: The microsecond offset within the represented second, rounded either up or down and padded to 6 digits with leading 0s.
52
+
// - %9f: The nanosecond offset within the represented second, padded to 9 digits with leading 0s.
53
+
//
54
+
// Time offsets:
55
+
//
56
+
// - %z: The UTC offset in the format ±HHMM, preceded always by the sign ('+' or '-'), and padded to 4 digits with leading zeros. See notes (6), (7), and (8).
57
+
// - %Ez: Equivalent to %z, except that an offset of +0000 is formatted at 'Z', and other offsets as ±HH:MM. See notes (6) and (7).
45
58
//
46
59
// When formatting using specifiers that represent padded decimals, leading 0s can be omitted using the '-' character after the '%'.
47
60
// For example, '%m' may produce the string '04' (for March), but '%-m' produces '4'.
@@ -66,7 +79,7 @@ import (
66
79
//
67
80
// Notes:
68
81
//
69
-
// 1. When 2-digit years are parsed, they are converted according to the POSIX and ISO C standards:
82
+
// 1. When 2-digit years are parsed (%y or %Ey), they are converted according to the POSIX and ISO C standards:
70
83
// values 69–99 are mapped to 1969–1999, and values 0–68 are mapped to 2000–2068.
71
84
// 2. When a date is parsed in combination with a day of year (%j), and/or an ISO week-based date (%G and/or %V),
72
85
// an error will be returned if the represented dates to not match.
@@ -75,15 +88,17 @@ import (
75
88
// The day of the week is otherwise ignored - it does not have any effect on the result.
76
89
// 4. When a time represented in the 12-hour clock format (%I) is parsed, and no time of day (%P or %p) is present,
77
90
// the time of day is assumed to be before noon, i.e. am or AM.
78
-
// 5. When a time is parsed that contains the time of day (%P or %p), any hour (%H) that is present must be valid
79
-
// on the 12-hour clock.
91
+
// 5. When a time is parsed that contains the time of day (%P or %p), any hour (%H) that is present
92
+
// must be valid on the 12-hour clock.
80
93
// 6. When UTC offsets are parsed (%z or %Ez) into a type which do not include a time offset element,
81
94
// the offset present in the string is ignored.
82
95
// When UTC offsets are formatted from a type which does not include a time offset element,
83
96
// the offset will not be present in the returned string.
84
97
// 7. When UTC offsets are parsed (%z or %Ez), the shorted form of ±HH is accepted.
85
98
// However, when formatted, only the full forms are returned (either ±HHMM or ±HH:MM).
86
99
// 8. When %z is used for parsing a UTC offset, 'Z' can be used to represent an offset of +0000.
100
+
// 9. When parsing partial years (%Ey and %C) in combination with a full year (%Y or %EY),
101
+
// an error will be returned if the represented years to not match.
0 commit comments