$ 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
Last active
June 21, 2018 08:42
-
-
Save tkuchiki/fa42cf4ceea0c882aa38 to your computer and use it in GitHub Desktop.
golang で timezone 変更
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment