I use getTimezoneOffset()
to get the offset in minutes for a given date object. Is is possible to use javascript to get timezone offset of a city or a country?
for example:
var offset = getCityOffset("Miami"); // returns -240
To get the current browser's time zone, you can use the getTimezoneOffset() method from the JavaScript Date object. The getTimezoneOffset() returns the time difference, in minutes, between UTC time and local time.
The JavaScript getTimezoneOffset() method is used to find the timezone offset. It returns the timezone difference in minutes, between the UTC and the current local time. If the returned value is positive, local timezone is behind the UTC and if it is negative, the local timezone if ahead of UTC.
The . getTimezoneOffset() method should work. This will get the time between your time zone and GMT. You can then calculate to whatever you want.
You can't change the Date object's behavior to get it to use a different time zone just by adding or subtracting an offset. It will still use the local time zone of where it runs, for any function that requires a local time, such as . toString() and others.
No, there is nothing built-in to javascript which allows you to get the number of minutes to offset for specific time zones/cities.
getTimeZoneOffset
works for the current browser's settings
MomentJS Timezone extensions has some of this sort of functionality, which is of course reliant on the MomentJS library.
If you have access to Lat/Long values, then google provide a timezone API
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With