Skip to content

Instantly share code, notes, and snippets.

@tkuchiki
Last active June 21, 2018 08:42
Show Gist options
  • Save tkuchiki/fa42cf4ceea0c882aa38 to your computer and use it in GitHub Desktop.
Save tkuchiki/fa42cf4ceea0c882aa38 to your computer and use it in GitHub Desktop.
golang で timezone 変更
package main
import (
"fmt"
"time"
)
func main() {
now := time.Now()
// current timezone & offset
zone, offset := time.Now().In(time.Local).Zone()
fmt.Println(zone, offset)
fmt.Println(now)
// UTC
loc, _ := time.LoadLocation("UTC")
zone, offset = time.Now().In(loc).Zone()
fmt.Println(zone, offset)
fmt.Println(now.In(loc))
// FixedZone to EST
loc, _ = time.LoadLocation("America/New_York")
zone, offset = time.Now().In(loc).Zone()
loc = time.FixedZone(zone, offset)
fmt.Println(zone, offset)
fmt.Println(now.In(loc))
}
$ go run main.go
JST 32400
2016-02-12 16:41:00.361450035 +0900 JST
UTC 0
2016-02-12 07:41:00.361450035 +0000 UTC
EST -18000
2016-02-12 02:41:00.361450035 -0500 EST
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment