Unix timestamps in Go
Everything Go needs for Unix timestamps: the current epoch time in seconds and milliseconds, timestamp-to-date and date-to-timestamp conversion, and ISO 8601 parsing. Go's parsing quirk is famous: layouts are written as the reference time “Mon Jan 2 15:04:05 MST 2006”, but for timestamps and ISO strings you rarely need a custom layout at all. There's a live converter at the bottom for checking any value the snippets produce.
Get the current Unix timestamp
seconds := time.Now().Unix() // 1700000000
millis := time.Now().UnixMilli() // 1700000000000 (Go 1.17+)Convert a timestamp to a time.Time
t := time.Unix(1700000000, 0).UTC()
// 2023-11-14 22:13:20 +0000 UTCtime.Unix returns the local-zone rendering; add .UTC() when you want UTC (the instant is the same either way).
Convert a time.Time to a timestamp
seconds := t.Unix()
millis := t.UnixMilli()Parse and format ISO 8601 (RFC 3339)
t, err := time.Parse(time.RFC3339, "2023-11-14T22:13:20Z")
s := t.Format(time.RFC3339)time.RFC3339 covers the ISO strings APIs actually exchange; reach for a custom reference-time layout only for nonstandard formats.
Check a value
Detected: Unix timestamp (seconds)
Your timezone
UTC · GMT+00:00 · UTC
Tue, Nov 14, 2023, 10:13:20 PM
Common formats
UTC
Tue, Nov 14, 2023, 10:13:20 PM
ISO 8601
2023-11-14T22:13:20.000Z
Unix (seconds)
1700000000
Unix (millis)
1700000000000
Relative
…
World clock
Los Angeles PST
Tue, Nov 14, 2023, 02:13:20 PM
GMT-08:00
Chicago CST
Tue, Nov 14, 2023, 04:13:20 PM
GMT-06:00
New York EST
Tue, Nov 14, 2023, 05:13:20 PM
GMT-05:00
London GMT
Tue, Nov 14, 2023, 10:13:20 PM
GMT+00:00
Paris CET
Tue, Nov 14, 2023, 11:13:20 PM
GMT+01:00
Kolkata IST
Wed, Nov 15, 2023, 03:43:20 AM
GMT+05:30
Shanghai CST
Wed, Nov 15, 2023, 06:13:20 AM
GMT+08:00
Tokyo JST
Wed, Nov 15, 2023, 07:13:20 AM
GMT+09:00
Sydney AEDT
Wed, Nov 15, 2023, 09:13:20 AM
GMT+11:00
Common questions
- Why does Go use “2006-01-02” instead of “YYYY-MM-DD”?
- Layouts are written as a concrete reference moment, Mon Jan 2 15:04:05 MST 2006, chosen so the fields count 1 2 3 4 5 6 7. It looks odd but makes layouts unambiguous. For standard formats, the time.RFC3339 constant means never writing one.
- Does a time.Time carry a timezone?
- It carries a Location used for rendering, but the instant is absolute: comparisons and Unix() are location-independent. Two times can be Equal() while printing differently.
- How do I get monotonic-safe durations?
- time.Since(start). Go embeds a monotonic clock reading in time.Now() values, so elapsed-time math is immune to wall-clock jumps. Unix timestamps, by contrast, are wall-clock and can step.