DevToolsForYou

Unix Timestamp Converter in Go — Code Examples

Unix Timestamp Converter in GoUse the online tool →

A Unix timestamp is the number of seconds (or milliseconds) since 1 January 1970 00:00:00 UTC. Here is how to get the current timestamp, convert to a human-readable date, and parse date strings back to timestamps in each language.

Go's time package uses int64 for Unix timestamps. time.Unix() converts to a time.Time value; .Unix() on a time.Time returns the epoch seconds.

Go
package main

import (
    "fmt"
    "time"
)

func main() {
    // Current timestamp
    nowSec := time.Now().Unix()          // seconds
    nowMs  := time.Now().UnixMilli()     // milliseconds (Go 1.17+)
    nowNs  := time.Now().UnixNano()      // nanoseconds
    fmt.Println(nowSec, nowMs, nowNs)

    // Timestamp → time.Time (UTC)
    t := time.Unix(1700000000, 0).UTC()
    fmt.Println(t)                       // 2023-11-14 22:13:20 +0000 UTC
    fmt.Println(t.Format(time.RFC3339))  // 2023-11-14T22:13:20Z

    // time.Time → timestamp
    ts := time.Date(2023, 11, 14, 22, 13, 20, 0, time.UTC).Unix()
    fmt.Println(ts) // 1700000000

    // Local timezone
    loc, _ := time.LoadLocation("Asia/Kolkata")
    tLocal := t.In(loc)
    fmt.Println(tLocal.Format("2006-01-02 15:04:05 MST"))
}
Notes & gotchas
  • Go's reference time is Mon Jan 2 15:04:05 MST 2006 — use these exact values in format strings.
  • time.Unix(sec, nsec) — pass 0 for nanoseconds if you only have seconds.
  • Use time.LoadLocation() with IANA timezone names (e.g. 'America/New_York') for DST-aware conversion.
Try it in your browser

Need to epoch/unix converter without writing code? The Unix Timestamp Converter runs entirely in your browser — paste your input and get the result instantly. No signup, no install, no data sent to a server.

Open Epoch/Unix Converter
Unix Timestamp Converter in other languages