Unix Timestamp in Go
Use the standard `time` package. Go's time handling is excellent and stdlib-only.
Common Operations
Get current Unix timestamp (seconds)
ts := time.Now().Unix() // 1706745600
Get current Unix timestamp (milliseconds)
tsMs := time.Now().UnixMilli() // 1706745600000
Convert Unix timestamp to time.Time
t := time.Unix(1706745600, 0) fmt.Println(t.UTC()) // 2024-01-31 22:40:00 +0000 UTC
Convert time.Time to Unix timestamp
t, _ := time.Parse(time.RFC3339, "2024-01-31T22:40:00Z") ts := t.Unix() // 1706740800
Format as ISO 8601
iso := time.Now().UTC().Format(time.RFC3339) // '2024-01-31T22:40:00Z'
Convert to specific timezone
loc, _ := time.LoadLocation("America/Los_Angeles")
t := time.Unix(1706745600, 0).In(loc)
// 2024-01-31 14:40:00 -0800 PST