In Vanilla JavaScript (i.e. without using Moment.js).
I have a server returning a timezone string, like Asia/Tokyo
America/New_York
etc...
That timezone is independent from the user current timezone. So the server can return Asia/Tokyo
when my current OS timezone is America/New_York
from the server given timezone, I would like to format it to something like =>
UTC+09:00 Asia/Tokyo
So in simple, I just want, from a given timezone, to find the UTC Offset of that timezone.
There is a native function getTimezoneOffset
in JS, but I can't find a setTimezone
I tried to do something like
var d = new Date()
new Date(d.toLocaleString('en-US', { timeZone: 'Asia/Tokyo' })).getTimezoneOffset()
but this always return my current offset.
How can I do this ?
Asia/Tokyo
I want to have the offset ofAsia/Tokyo
based on UTC and not on my current timezone (america/newYork)Date
API, I don't see any support for specifying (or querying) any other time zones. What makes you think others are "still supported by date"?