const d = new Date(); // get 'now'
d.getDay(); // 0 = Sunday, 1 = Monday... in my browser's timezone.
d.toLocaleDateString('en-GB', { timeZone: 'NZ' }); // formatted date in NZ
console.log(d);
How can I get the numeric day in NZ? toLocaleDateString
does not support weekday: 'numeric'
.
The only way I can think of is to map the day to Sat, Sun ... and then use a {Sun: 0...}
map to map it back to a number?!
EDIT: To be clear: the day-of-the week for a given time will be different in different timezones. But Date.getDay()
only returns the numeric date in the browser's timezone. toLocaleDateString
can present the date in different timezones, however it does not appear to support outputting the day/weekday as a number, which seems a surprising omission.
Also, I do not want to use some deprecated massive library (looking at you, moment) but instead I want to use vanilla Javascript.