Created
July 14, 2014 22:51
-
-
Save rickt/8943bc09a787842b59df to your computer and use it in GitHub Desktop.
example go code to load/print a time in another TZ
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" | |
| ) | |
| const ( | |
| datelayout string = "2006-01-02 15:04:05" | |
| ) | |
| func main() { | |
| fmt.Printf("now in default TZ=%s\n", time.Now()) | |
| location, _ := time.LoadLocation("Asia/Tokyo") | |
| fmt.Printf("loaded location=%s\n", location) | |
| fmt.Printf("now in Asia/Tokyo=%s\n", time.Now().In(location)) | |
| } | |
| // Expected Output: | |
| // | |
| // now in default TZ=2014-07-14 15:50:32.494723966 -0700 PDT | |
| // loaded location=Asia/Tokyo | |
| // now in Asia/Tokyo=2014-07-15 07:50:32.495017166 +0900 JST |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment