Reputation: 3922
I'm facing an issue where Go time parse is returning different values for two times in the same timezone.
func timeParse() {
layout := "Mon, 2 Jan 2006 03:04:05 -0700 (MST)"
value1 := "Mon, 18 Jan 2016 01:48:52 -0800 (PST)"
value2 := "Tue, 19 Jan 2016 17:49:33 -0800 (PST)"
t1, _ := time.Parse(layout, value1)
fmt.Println(t1)
t2, _ := time.Parse(layout, value2)
fmt.Println(t2)
}
Output:
2016-01-18 01:48:52 -0800 PST
0001-01-01 00:00:00 +0000 UTC
Notice that the second one didn't parse properly.
Upvotes: 1
Views: 299
Reputation: 3922
Found my mistake. The layout expects a 24 hour times. Fixed with:
layout := "Mon, 2 Jan 2006 15:04:05 -0700 (MST)"
Upvotes: 1