Skip to content

Instantly share code, notes, and snippets.

@rickt
Created July 14, 2014 22:51
Show Gist options
  • Select an option

  • Save rickt/8943bc09a787842b59df to your computer and use it in GitHub Desktop.

Select an option

Save rickt/8943bc09a787842b59df to your computer and use it in GitHub Desktop.
example go code to load/print a time in another TZ
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