Generate the current timestamp
These three values come from the same instant:
now := time.Now()
fmt.Println(now.Unix()) // seconds
fmt.Println(now.UnixMilli()) // milliseconds
fmt.Println(now.UnixNano()) // nanosecondsPlace this fragment inside main, with the fmt and time imports from the program below.
Convert seconds or milliseconds
In Go 1.17 or later, use time.Unix for seconds and time.UnixMilli for milliseconds. This complete program produces the same instant with both units.
package main
import (
"fmt"
"time"
)
func main() {
seconds := int64(1711972800)
milliseconds := int64(1711972800000)
date := time.Unix(seconds, 0).UTC()
sameDate := time.UnixMilli(milliseconds).UTC()
fmt.Println(date.Format(time.RFC3339)) // 2024-04-01T12:00:00Z
fmt.Println(date.Equal(sameDate)) // true
fmt.Println(date.Unix()) // 1711972800
fmt.Println(date.UnixMilli()) // 1711972800000
}For the current instant: time.Now().Unix() or time.Now().UnixMilli(). The time zone does not change these numbers.
Format with the Go reference date
The layout uses the components of January 2, 2006 at 15:04:05: 2006 represents the year, 01 the month and 02 the day. This fragment reuses date from above.
fmt.Println(date.Format("02/01/2006 15:04:05"))
// 01/04/2024 12:00:00Parse a date with its UTC offset
parsed, err := time.Parse(time.RFC3339, "2024-04-01T14:00:00+02:00")
if err != nil {
panic(err) // In an API, return a validation error.
}
fmt.Println(parsed.Unix()) // 1711972800An offset of +02:00 does not describe seasonal clock changes in Paris. To display a geographical time zone, load its location and handle any error.
paris, err := time.LoadLocation("Europe/Paris")
if err != nil {
panic(err)
}
fmt.Println(parsed.In(paris).Format(time.RFC3339))
// 2024-04-01T14:00:00+02:00Negative dates, precision and durations
time.Unix(-1, 0).UTC() represents December 31, 1969 at 23:59:59 UTC. Avoid floating-point numbers when transporting nanoseconds. UnixNano() does not cover every date representable by time.Time: its range is limited by a signed 64-bit integer.
To time an operation, keep start := time.Now() and then use time.Since(start), rather than subtracting two serialized timestamps.
Test a value and explore further
Paste your results into the Unix converter, check units and precision or compare with conversion in Rust.
Official references
Go — time package and monotonic clocks · Format and the reference date · UnixNano limits
English version published September 26, 2026.