Skip to content

Instantly share code, notes, and snippets.

@r002
Last active June 26, 2021 07:49
Show Gist options
  • Save r002/37fec489020cc20c51cf4e10727865cc to your computer and use it in GitHub Desktop.
Save r002/37fec489020cc20c51cf4e10727865cc to your computer and use it in GitHub Desktop.
Formatting datetime strings in Go
// https://play.golang.org/p/6RkCCDQQ67Q
func main() {
loc, _ := time.LoadLocation("America/New_York")
t, _ := time.Parse(time.RFC3339, "2021-05-03T20:27:21Z")
fmt.Println(t.In(loc)) // 2021-05-03 16:27:21 -0400 EDT
fmt.Println(t.In(loc).Format(time.ANSIC)) // Mon May 3 16:27:21 2021
fmt.Println(t.In(loc).Format("2006-01-02")) // 2021-05-03
fmt.Println(t.In(loc).Format(time.RFC3339)) // 2021-05-03T16:27:21-04:00
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment