Go Unix Timestamp Converter

Convert Unix timestamps in Go with live parser and time package snippets. Unix(), UTC, and locations.

⏱ UnixLi — Live Tool All processing local · No data sent
—
unix seconds · now

Smart Universal Parser

// Paste Unix seconds/ms, ISO 8601, RFC 2822, or a human date.

Developer Snippets

// Copy-ready code — current timestamp injected automatically.

Unix timestamps in Go

Go’s standard time package covers everything you need for epoch conversions without third-party libraries: reading the clock, converting seconds or milliseconds to a time.Time, formatting with Go’s reference-date layouts, and applying IANA time zones. The live parser above checks any timestamp, and the snippet panel generates a runnable Go program with the current value filled in. Conversions happen in your browser only; no input leaves the tab.

Current time: Unix(), UnixMilli(), UnixNano()

Go
now := time.Now()
secs := now.Unix()       // int64 seconds, e.g. 1715429912
ms := now.UnixMilli()    // int64 milliseconds (Go 1.17+)
ns := now.UnixNano()     // int64 nanoseconds

UnixMilli and UnixMicro were added in Go 1.17. Before that, people wrote UnixNano() / 1e6, which you will still see in older code.

Epoch to time.Time with time.Unix

time.Unix(sec, nsec) builds a time.Time from seconds plus nanoseconds. The result carries the local location of the machine, so call .UTC() for predictable output in logs and APIs. For milliseconds, use time.UnixMilli(ms).

Go
package main

import (
	"fmt"
	"time"
)

func main() {
	t := time.Unix(1715429912, 0).UTC()
	fmt.Println(t.Format(time.RFC3339))         // 2024-05-11T12:18:32Z
	fmt.Println(t.Format("2006-01-02 15:04:05")) // 2024-05-11 12:18:32

	loc, err := time.LoadLocation("America/New_York")
	if err != nil {
		panic(err)
	}
	fmt.Println(t.In(loc).Format("Mon Jan 2 15:04:05 MST 2006"))
	// Sat May 11 08:18:32 EDT 2024

	fmt.Println(time.UnixMilli(1715429912000).UTC()) // 2024-05-11 12:18:32 +0000 UTC
}

This output confirms 1715429912 is Saturday, May 11, 2024 at 12:18:32 UTC, and 08:18:32 EDT in New York.

Understanding Go’s layout: 2006-01-02 15:04:05

Go does not use %Y-%m-%d tokens. A layout is the reference moment Mon Jan 2 15:04:05 MST 2006 written the way you want your output to look. Each component has a fixed value: year 2006, month 01 or Jan, day 02, hour 15 (or 03 for 12-hour), minute 04, second 05, zone MST or -0700. A handy mnemonic is 1-2-3-4-5-6-7: month 1, day 2, hour 3 (15), minute 4, second 5, year 6, zone −7.

If you write a real date as the layout, such as "2024-05-11", Go reads those digits as layout tokens and prints garbage. Prefer the predefined constants time.RFC3339, time.DateTime ("2006-01-02 15:04:05", Go 1.20+), and time.DateOnly.

Parsing strings back to epoch

Go
p, err := time.Parse(time.RFC3339, "2024-05-11T12:18:32Z")
if err != nil {
	return err
}
fmt.Println(p.Unix()) // 1715429912

time.Parse treats strings without zone information as UTC. Use time.ParseInLocation when the input is a local wall-clock time.

Timestamps in JSON and databases

By default, encoding/json marshals a time.Time as an RFC 3339 string with nanosecond precision, such as "2024-05-11T12:18:32Z". If your API contract uses numeric epoch seconds instead, declare the field as int64 and convert with t.Unix() and time.Unix(), or write a small wrapper type with custom MarshalJSON and UnmarshalJSON methods. Whichever you choose, document the unit in the field name (created_at_unix, expires_ms) so clients in other languages don’t guess wrong. Most SQL drivers scan timestamp columns straight into time.Time. Call .UTC() before writing so the stored value never depends on the server’s location.

Common Go time pitfalls

Frequently asked questions

How do I get the current Unix timestamp in Go?

Use time.Now().Unix() for seconds or time.Now().UnixMilli() for milliseconds. Both return int64.

How do I convert a Unix timestamp to time.Time?

Call time.Unix(sec, 0), and add .UTC() for UTC output. For milliseconds use time.UnixMilli(ms).

Why does Go use 2006-01-02 as a date format?

Go layouts are written using the reference time Mon Jan 2 15:04:05 MST 2006. You describe the output format by writing that moment in the shape you want.

Why does time.LoadLocation fail in my Docker container?

The image has no timezone database. Add import _ "time/tzdata" to embed it, or install the tzdata package in the image.

Should I compare time.Time values with ==?

No. Use Equal, Before, and After. The == operator also compares location and monotonic clock data.

Does this converter run locally?

Yes. All parsing and snippet generation happens in your browser; nothing is uploaded.

Related tools