Intl.DateTimeFormat object which is available in all modern browsers and returns the language-specific date and time formatting methods.
Here is how it works. Simply open the developer console in your web browser and run the following code:
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone; console.log(timezone); // Africa/Casablanca
This is the exact time zone but you can also get the offset in minutes of your timzeone using
Get timezone offset in minutes
getTimezoneOffset() function gives you the offset, in minutes, from Coordinated Universal Time to your current time zone.
Positive is returned if the local time zone is later than UTC, and negative if it is earlier. The
getTimezoneOffset() is available in all modern browsers.
Let's take the following example:
const date = new Date(); console.log(date.getTimezoneOffset()); // -60
The difference between my time zone and UTC is 60 minutes which means one hour.
Please note that Daylight Saving Time (DST) causes the returned value to fluctuate throughout the year.
The result of a call to
getTimezoneOffset() for a time zone that transitions into and out of Daylight Saving Time (DST) each year can vary by up to 60 minutes.
- Author: Ahmed Bouchefra Follow @ahmedbouchefra
✋If you have any questions about this article, ask them in our GitHub Discussions 👈 community. You can also
❤️ Like our page and subscribe to our feed for updates!
Find a list of emojis to copy and paste