Unix Timestamp in Go
Go's time package provides Unix() and UnixMilli() methods on time.Time. These are simple, idiomatic, and don't require external dependencies.
Code Examples
Current timestamp (seconds)
import "time" time.Now().Unix()
Returns the current Unix timestamp in seconds as an int64. The idiomatic Go way.
Current timestamp (milliseconds)
import "time" time.Now().UnixMilli()
Available since Go 1.17. Returns milliseconds since epoch as int64.
Current timestamp (nanoseconds)
import "time" time.Now().UnixNano()
Returns nanoseconds since epoch. Useful for high-resolution benchmarking. Overflows int64 around year 2262.
Convert timestamp back to time.Time
import "time" t := time.Unix(timestamp, 0).UTC()
The second argument is nanoseconds offset. Pass 0 for whole-second precision. Call .UTC() to normalize the timezone.
Format timestamp as string
import "time" t := time.Unix(timestamp, 0).UTC() formatted := t.Format(time.RFC3339)
Go uses reference-time formatting (2006-01-02T15:04:05Z07:00). time.RFC3339 produces ISO 8601 output.
Note
Go's time.Now().Unix() is seconds since epoch, consistent with C and Python. The UnixMilli() and UnixMicro() helpers were added in Go 1.17 — before that, developers multiplied by 1000 manually. All time.Time values in Go are timezone-aware.
Need to convert a specific timestamp? Use the live converter — paste any epoch value and see the human-readable date instantly.
← Open the converter