Skip to content

Instantly share code, notes, and snippets.

@zgiber
Created August 17, 2020 15:43
Show Gist options
  • Save zgiber/a2a0e0a07f0d1b7c635c54ca97fe263e to your computer and use it in GitHub Desktop.
Save zgiber/a2a0e0a07f0d1b7c635c54ca97fe263e to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"time"
)
var (
dateTimeISO8601format1 = "2006-01-02T15:04:05.999Z07:00"
dateTimeISO8601format2 = "2006-01-02T15:04:05.999-07:00"
dateTimeISO8601format3 = "2006-01-02T15:04:05Z07:00"
dateTimeISO8601format4 = "2006-01-02T15:04:05-07:00"
)
func main() {
location, err := time.LoadLocation("America/Los_Angeles")
if err != nil {
panic(err)
}
t := time.Now().Add(259328762398 * time.Millisecond)
fmt.Println(t.Format(dateTimeISO8601format1))
fmt.Println(t.Format(dateTimeISO8601format2))
fmt.Println(t.Format(dateTimeISO8601format3))
fmt.Println(t.Format(dateTimeISO8601format4))
t = t.In(location)
fmt.Println(t.Format(dateTimeISO8601format1))
fmt.Println(t.Format(dateTimeISO8601format2))
fmt.Println(t.Format(dateTimeISO8601format3))
fmt.Println(t.Format(dateTimeISO8601format4))
location, err = time.LoadLocation("Europe/Budapest")
if err != nil {
panic(err)
}
t = t.In(location)
fmt.Println(t.Format(dateTimeISO8601format1))
fmt.Println(t.Format(dateTimeISO8601format2))
fmt.Println(t.Format(dateTimeISO8601format3))
fmt.Println(t.Format(dateTimeISO8601format4))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment