Go Datetime Format Builder
Build Go time.Format() strings interactively. Go's format system is based on a single reference time — Mon Jan 2 15:04:05 MST 2006 — where each component is a specific representation of that moment. Click tokens to compose your format string, see a live preview, and copy the result.
Build Your Format String
Examples
Year
Month
Weekday
Day
Hour
Minute
Second
AM/PM
Timezone
Subsecond
Separators (literals)
Preview
Output
Timezone name preview may differ from Go's output depending on the system timezone database.
Quick Reference
| Token | Category | Example output | Description |
|---|---|---|---|
| 2006 | Year | 2024 | 4-digit year |
| 06 | Year | 24 | 2-digit year |
| January | Month | March | Full month name |
| Jan | Month | Mar | Abbreviated month name (3 chars) |
| 01 | Month | 03 | Month number, zero-padded |
| 1 | Month | 3 | Month number, no padding |
| Monday | Weekday | Tuesday | Full weekday name |
| Mon | Weekday | Tue | Abbreviated weekday name (3 chars) |
| 02 | Day | 09 | Day of month, zero-padded |
| _2 | Day | 9 | Day of month, space-padded |
| 2 | Day | 9 | Day of month, no padding |
| 15 | Hour | 14 | Hour (24-hour clock), zero-padded |
| 03 | Hour | 02 | Hour (12-hour clock), zero-padded |
| 3 | Hour | 2 | Hour (12-hour clock), no padding |
| 04 | Minute | 05 | Minute, zero-padded |
| 4 | Minute | 5 | Minute, no padding |
| 05 | Second | 09 | Second, zero-padded |
| 5 | Second | 9 | Second, no padding |
| PM | AM/PM | AM | Uppercase AM or PM |
| pm | AM/PM | am | Lowercase am or pm |
| MST | Timezone | EST | Timezone abbreviation |
| -0700 | Timezone | -0500 | UTC offset, no colon |
| -07:00 | Timezone | -05:00 | UTC offset, with colon |
| -07 | Timezone | -05 | UTC offset, hours only |
| Z0700 | Timezone | Z or -0500 | UTC offset; Z when UTC |
| Z07:00 | Timezone | Z or -05:00 | UTC offset with colon; Z when UTC |
| .000 | Subsecond | .123 | Milliseconds, trailing zeros kept |
| .000000 | Subsecond | .123456 | Microseconds, trailing zeros kept |
| .000000000 | Subsecond | .123456789 | Nanoseconds, trailing zeros kept |
| .999 | Subsecond | .123 | Milliseconds, trailing zeros removed |
| .999999 | Subsecond | .123456 | Microseconds, trailing zeros removed |
| .999999999 | Subsecond | .123456789 | Nanoseconds, trailing zeros removed |
Frequently Asked Questions
Why does Go use numbers like 01, 02, 2006 in its format strings?
Go's time.Format() does not use placeholder tokens like %Y or YYYY. Instead, every format component is expressed as a specific representation of one reference moment: Mon Jan 2 15:04:05 MST 2006. That moment was chosen so that each component has a distinct value — month is 1, day is 2, hour is 15, minute is 4, second is 5, year is 2006. When you write 2006-01-02 in a Go format string, Go recognises 2006 as the year, 01 as the zero-padded month, and 02 as the zero-padded day because those are exactly the values they hold in the reference time.
What happens if I write a format string with tokens from another language, like %Y or YYYY?
Those characters are treated as literals. %Y produces the text %Y in the output, not the year. YYYY produces the text YYYY. This is one of the most common mistakes developers make when switching to Go from Python, PHP, or JavaScript. The reference time system means Go format strings look like a real date — 01/02/2006 is a valid Go format string because it happens to spell out the reference time's month, day, and year.
What is the difference between 2, 02, and _2 for the day of the month?
All three produce the day of the month but with different padding. 02 zero-pads single-digit days (1 becomes 01). _2 space-pads single-digit days (1 becomes 1, with a leading space). 2 applies no padding (1 stays 1). The same distinction applies to hours (3 vs 03), minutes (4 vs 04), seconds (5 vs 05), and months (1 vs 01). _2 is the only space-padded token.
How does Go handle timezone formatting?
Go provides six timezone offset tokens. -0700 emits a signed four-digit offset like -0500. -07:00 adds a colon: -05:00. -07 emits hours only: -05. Z0700 and Z07:00 behave like their dash counterparts but emit Z instead of +0000 when the time is in UTC. MST emits the timezone abbreviation. In this preview tool, timezone names come from the browser's Intl.DateTimeFormat API and may differ slightly from what Go reports on a particular server operating system.
What are the .000 and .999 subsecond tokens and when should I use each?
Both families format fractional seconds. .000, .000000, and .000000000 produce milliseconds, microseconds, and nanoseconds respectively, always including trailing zeros. .999, .999999, and .999999999 do the same but omit trailing zeros — if a timestamp has no fractional part, .999 emits nothing at all. Use the .000 family when you need a fixed-width output (e.g., log timestamps). Use the .999 family when you want compact output that omits insignificant zeros. In Go, these tokens must immediately follow a seconds token (05 or 5) in the format string; they are not standalone tokens.
