5 ms·
Golang went with the bizarre decision of using a specific timestamp as a template for date format strings. So in Go, instead of having to remember impossible th
by tdeck 5y ago
Golang went with the bizarre decision of using a specific timestamp as a template for date format strings. So in Go, instead of having to remember impossible things like "%Y stands for year" and "%H is a two-digit hour", I simply need to recall that the canonical time is Monday, January 2nd 2006 at 15:04:05.
- runarberg 5y agoIn JavaScript you actually use `Intl.DateTimeFormat`[1] to format datetimes, which takes in a pretty descriptive configuration object with keys such as `month: "short"`, `hour: "2-digit"`, and `hour12: true`. This is missing in the OP explainer, so I created a PR[2]. 1: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... 2: https://github.com/you-dont-need/You-Dont-Need-Momentjs/pull/116 https://github.com/you-dont-need/You-Dont-Need-Momentjs/pull...
- dvdkon 5y agoAnd it fills a completely different usecase to arbitrary date formats. For one, there's no parsing. And you have to make do with what the browser provides with no guarantee of stability.
- p2t2p 5y agoTo be honest for me it is much easier to memorise %Y and friends then this special date. I feel like this canonical date is easier to write documentation for but harder to use.
- hn_throwaway_99 5y agoOK, I'm not a Go programmer so was struggling to figure out what was going on, until reading that the "canonical" date for formatting is essentially: 01/02 03:04:05PM '06 -0700 I actually think that's a really good idea. Sure, it may easier to remember "YYYY-MM-DD" than "2006-01-02" at first, but I think it helps a lot in many other cases, e.g. you don't need to remember what is exactly meant by MM and MMM and MMMM, you could just create your format string as "January 2, 2006" or "Jan 2, 2006".
- tdeck 5y agoNever realized that, I guess because nobody writes timestamps in "month, day, time, year, zone offset" order.