Essential Go Time and date  Suggest an edit

Parse time

Parsing is the reverse of formatting:

s := "2017-04-09 03:38:45.000 UTC"
t, err := time.Parse("2006-02-01 15:04:05.000 MST", s)
if err != nil {
	log.Fatalf("time.Parse() failed wiht '%s'\n", err)
fmt.Printf("year: %d, month: %d, day: %d\n", t.Year(), t.Month(), t.Day())
year: 2017, month: 9, day: 4

Parsing template uses the same style as formatting.

What if you prefer strftime style of parsing time? That’s available too.

  ↑ ↓ to navigate     ↵ to select     Esc to close