Formatting time
Time can be a pain in the ass, and especially if you’re new to formatting time in Go.
If you’re trying to format a date and give any old reference time, you’ll likely get a date different than what you expected. This is because Go requires a specific timepoint. A specific timepoint is required so there is no ambiguity in the requested format.
This timepoint is:
Mon Jan 2 15:04:05 -0700 MST 2006
so in practice, this might look like:
now.Format("2006-02-01")
For better understanding about what I mean by amiguity, ponder this. If the reference date of my requested format is 01-01-2020. I cannot be sure whether the month or day is in the first slot.
Enjoy Reading This Article?
Here are some more articles you might like to read next: