A Utility for Parsing Dates and Times

Let’s learn about the utility for parsing dates and times.

On a rare occasion, a situation can happen when we do not know anything about our input. If we do not know the exact format of our input, then we need to try matching our input against multiple Go strings without being sure that we are going to succeed in the end. This is the approach that the example uses. The Go matching strings for dates and times can be tried in any order.

If we are matching a string that only contains the date, then our time will be set to 00:00 by Go and will most likely be incorrect. Similarly, when only matching the time, our date will be incorrect and should not be used.

Get hands-on with 1400+ tech skills courses.