Its so surprising to see JavaScript not having a easy to use format for dates.
I'm trying do get this format (example in python)
>>> datetime.now().strftime("%Y%m%d")
'20221228'
I did find that Intl.DateTimeFormat can do some format the Date() objects. But from the docs I don't see how to make a custom format out of this.
There are canned formats en-US
en-GB
which it would be nice to define a format.
> var dateOptions = {year:'numeric', month:'numeric', day:'numeric'}
> console.log( Intl.DateTimeFormat('en-GB', dateOptions).format(Date.now()))
28/12/2022
> console.log( Intl.DateTimeFormat('en-US', dateOptions).format(Date.now()))
12/28/2022
It partially controls formatting but does anyone know how to actually control the output format with Intl.DateTimeFormat
to output YYYYMMDD?