Last active
June 26, 2021 07:49
-
-
Save r002/37fec489020cc20c51cf4e10727865cc to your computer and use it in GitHub Desktop.
Formatting datetime strings in Go
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
| // 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