I'm looking at a semi-old codebase where the following code is used to format a date in YYYY-MM-DD
format according to a user's locale:
new Date('2000-01-01').toLocaleDateString(navigator.language)
However, this doesn't work in Firefox because new Date('2000-01-01')
returns a datetime (time is 00:00) in UTC while toLocaleDateString
uses the user's local timezone, so the above will return "December 31, 1999"
for a user in the US.
What is the sane, safe way of doing this across browsers? Is it possible to do without one or more extra dependency?