Skip to content

Instantly share code, notes, and snippets.

@kisom
Last active December 16, 2015 15:29
Show Gist options
  • Save kisom/5456138 to your computer and use it in GitHub Desktop.
Save kisom/5456138 to your computer and use it in GitHub Desktop.
It appears time.Now().UTC().Unix() still returns a local timestamp. If this doesn't work, I'm not sure how to get a UTC timestamp.
package main
import "fmt"
import "time"
func main() {
local, _ := time.Now().Zone()
fmt.Println("Local timezone:", local)
fmt.Println("UNIX local timestamp:", time.Now().Unix())
fmt.Println("UNIX UTC timestamp:", time.Now().UTC().Unix())
}
$ go version
go version devel +d4c3e6c8b141 Wed Apr 24 10:40:29 2013 -0700 darwin/amd64
$ go run timestamp.go
Local timezone: MDT
UNIX local timestamp: 1366842519
UNIX UTC timestamp: 1366842519
$ go version
go version devel +ce5b441d2fc6 Sun Apr 14 09:22:57 2013 +1000 linux/amd64
$ go run timestamp.go
Local timezone: MDT
UNIX local timestamp: 1366843096
UNIX UTC timestamp: 1366843096
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment