Skip to content

Instantly share code, notes, and snippets.

@obutora
Created November 15, 2023 03:17
Show Gist options
  • Save obutora/808a2cf2593f5373a401bd58f863f849 to your computer and use it in GitHub Desktop.
Save obutora/808a2cf2593f5373a401bd58f863f849 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"time"
)
func main() {
jst, _ := time.LoadLocation("Asia/Tokyo")
a, _ := time.Parse("2006-01-02 15:04:05", "2018-01-01 00:00:00")
b, _ := time.Parse("2006-01-02 15:04:05 (MST)", "2018-01-01 00:00:00 (JST)")
c, _ := time.ParseInLocation("2006-01-02 15:04:05", "2018-01-01 00:00:00", jst)
d, _ := time.ParseInLocation("2006-01-02 15:04:05 (MST)", "2018-01-01 00:00:00 (UTC)", jst)
fmt.Println("a: ", a) // 2018-01-01 00:00:00 +0000 UTC
fmt.Println("b: ", b) // 2018-01-01 00:00:00 +0900 JST
fmt.Println("c: ", c) // 2018-01-01 00:00:00 +0900 JST
fmt.Println("d: ", d) // 2018-01-01 00:00:00 +0000 UTC
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment