Go time layout tokens.

Go has no tokens at all: you write the reference time itself — Mon Jan 2 15:04:05 MST 2006 — laid out the way you want your output to look, and the formatter pattern-matches your layout against it. The mnemonic is that the fields count 1 through 7 (month 1, day 2, hour 3, minute 4, second 5, year 6, zone 7). Names always render in English; there is no locale support in the standard library. There are no tokens for week numbers, quarters or eras.

TokenMeansExample
2006Four-digit year2006
06Two-digit year06
1Month number1
01Month number, padded01
JanMonth name, abbreviatedJan
JanuaryMonth name, fullJanuary
2Day of month2
02Day of month, padded02
002Day of year

Zero-padded to three digits; __2 gives the space-padded form. Added in Go 1.13.

2
MonWeekday, abbreviatedMon
MondayWeekday, fullMonday
15Hour, 24-hour clock, padded

Always zero-padded; Go has no unpadded 24-hour token.

15
3Hour, 12-hour clock3
03Hour, 12-hour clock, padded03
PMAM/PM marker

Write pm for lowercase output.

PM
04Minute, padded

A bare 4 gives the unpadded minute.

04
05Second, padded

A bare 5 gives the unpadded second.

05
.000Fractional seconds

Prints exactly as many digits as you write zeros; .999 trims trailing zeros instead.

000
-0700UTC offset, basic-0700
-07:00UTC offset, extended-07:00
MSTTime-zone name, shortMST

Examples render the reference instant, Mon, Jan 2 2006, 3:04:05 PM MST.

Literal text

No escaping exists. Any text that doesn't match a reference-time fragment passes through literally — which means literal text that LOOKS like a fragment (a lone 1, or the word Jan) will be treated as a field. There is no way to escape it; restructure the string instead.

Verified against Go standard library — time package constants.

Translate Go time layout