Go Time Layout Converter

Paste a strftime format string and get the Go layout, or paste a Go layout and get the strftime. Every directive is converted or named — nothing is guessed.

Nothing you paste is transmitted. There is no endpoint behind this page: the Go that does the conversion is compiled to WebAssembly and runs in this tab, so your format strings never leave the browser.

Why Go uses a date instead of directives

Most languages describe a time format with directives: %Y is the year, %d is the day. Go describes it by writing out one particular instant — Mon Jan 2 15:04:05 MST 2006 — and asking you to write it the way you want your own times written. The numbers are not arbitrary: they run 1 through 7 in order, for month, day, hour, minute, second, year and zone offset.

That is why a Go layout is readable at a glance and why it is easy to get subtly wrong. 2006-01-02 is a year, a month and a day. 2006-02-01 is a year, a day and a month, and it compiles, runs, and produces a plausible date every day of the month before the thirteenth.

What cannot be converted, and why that matters

The two notations are not the same size, and the gap runs in both directions.

strftime can print things a Go layout has no token for. An ISO 8601 week number, the century, the weekday as a number, the seconds since the epoch. None of those is a field of an instant the way a month is; they are computed from one. Go gives you time.Time.ISOWeek and int(t.Weekday()) and t.Unix() for exactly this reason, and none of them belongs in a layout string.

Go can print things strftime has no directive for. A fractional second attached to the seconds field, a numeric zone at seconds precision, and the ISO 8601 zone that renders a bare Z at the zero offset — which is what makes time.RFC3339 unspellable in strftime. %z would print +00:00 there, which looks right until someone runs it in Reykjavik.

This converter names every one of those instead of guessing, and when anything is refused it gives you no format string at all rather than a partial one. That is deliberate. A partial layout compiles and runs; it simply prints the wrong field, on some dates, in some zones, and the first sign of trouble is a log line nobody can reconcile.

Directives that are not POSIX

Several directives are real, widely used, and specific to glibc: %-d and its family drop the padding, %:z puts a colon in the numeric zone, %P gives lowercase am/pm. Refusing them would make this useless on the platform most Go is written for, so they are converted and flagged — the notes column says which ones the BSD and macOS strftime will not accept.

Every strftime directive, and what it becomes

This table is generated by the same code that does the conversion, so it cannot describe a directive the converter treats differently.

The other tools