Instead of using classical format specifiers like "YYYY", "MM", "HH", "mm" etc., this function uses the Date instance getters like getFullYear
, getMonth
, etc., with support for zero-padding.
For example, instead of:
"YYYY-MM-DD HH:mm:ss"
you can use:
"{FullYear}-{Month:2}-{Date:2} {Hours:2}:{Minutes:2}:{Seconds:2}"
Verbose, but more human-friendly. And can be done within 140 bytes!
@Alexei-B Thanks for the regexp suggestion. On top of those 4 characters, I shaved a whole bunch of characters by using arrow functions.
With regards to
.toUTCString()
, I think you missed the point. This is a generic formatter that allows you to format dates in any way you like.