Gone are the days where we needed libraries to simply format a date (yes I’m looking at you Moment.js). After ditching Moment.js about a year ago, because it’s not good with tree-shaking and immutability, I landed on Day.js.
This was definitely an upgrade compared to Moment.js purely looking at the size of the library you’re importing, but it still felt strange to use a library to format a date.
Say I want to convert a UTC date to a human readable, localized string.
The default already looks kind of ok, but my client wants it to be in Dutch, and wants the weekday to be written out fully (e.g. Wednesday).
For this case, we can use the
Super easy! And easy to customise too, you don’t have to remember to use capitals, different digits (like dd-MM-yyyy etc.). Formatting without options (just a locale) will format the date the default way:
So for simple conversions/formatting this can definitely do the trick, for more complex stuff (working with different timezones, adding/subtracting days…) I’d recommend using date-fns (https://github.com/date-fns/date-fns)!