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.

Frequently Asked Questions

How do I get the current Unix timestamp in Go?

Use time.Now().Unix() from the standard library's time package. It returns the current Unix time as an int64 — the number of seconds elapsed since January 1, 1970 UTC. No external packages needed.

What is the difference between Unix() and UnixMilli() in Go?

Unix() returns seconds since epoch (a 10-digit int64). UnixMilli() returns milliseconds (a 13-digit int64) and was added in Go 1.17. Use Unix() for most APIs and databases; use UnixMilli() when interfacing with JavaScript or Java systems that expect milliseconds.

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

Use time.Unix(seconds, 0). The second argument is additional nanoseconds — pass 0 for whole-second precision. Chain .UTC() to normalize the result to UTC: t := time.Unix(timestamp, 0).UTC()

Does Go's time package handle timezones automatically?

Yes. Every time.Time value in Go carries location (timezone) information. time.Now() uses the local system timezone. Call .UTC() to convert to UTC, or time.LoadLocation("America/New_York") to work with a specific timezone.

Why does time.Now().UnixNano() overflow?

int64 can hold nanoseconds until the year 2262. For timestamps before 1678 or after 2262, UnixNano() overflows — use Unix() (seconds) or UnixMilli() instead. For practically all modern use cases, UnixNano() is safe.

Main Epoch Converter

Use the homepage when you need epoch to date, date to epoch, or a full epoch converter

This Go guide shows how to create and parse Unix timestamps in code. If your next step is broader search intent like epoch converter, epoch to date, epoch time to date, or unix epoch converter, jump back to the live homepage tools to paste a raw Unix value, auto-detect seconds versus milliseconds, and copy the readable answer instantly.

Related Tools

More free tools for developers debugging timestamps, schedules, and text changes.