Thomas McGoey-Smith

Parsing Time in Go

I’ve been working with the Canada Post Tracking API and needed a simple way to parse the dates into a time type.

Basically I’m needing to parse this created_at:

2015-07-02

Using the constants in the format source code, I simply just did this:

t, _ := time.Parse("2006-01-02", "2015-07-02")

Where 2006 is stdLongYear, 01 is stdZeroMonth, and 02 is stdZeroDay.

Try the playground!

@tamcgoey on Jul 08, 2015

Enjoyed the article? Subscribe to my newsletter for more.

© Thomas McGoey-Smith (2014-2018). RSS.