How to get current time zone in JavaScript

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 returned value is positive if the local time zone is behind UTC and negative if the local time zone is ahead of UTC.

For example, if your time zone is UTC+5, the getTimezoneOffset() method will return -300 minutes:

const date = new Date();
const offset = date.getTimezoneOffset();
console.log(offset);    // -300

The getTimezoneOffset() works in all modern browsers, Internet Explorer 5 and higher.

Daylight Saving Time (DST) time zones

Note that the returned value is not always constant due to Daylight Saving Time (DST) time zones.

For a time zone that moves in and out of Daylight Saving Time (DST) every year, the number of offset minutes returned by calling getTimezoneOffset() can vary +/- 60 minutes.

For example, North America uses Pacific Standard Time (PST) during wintertime and Pacific Daylight Time (PDT) during summertime. The PST time is 8 hours behind UTC (UTC-08:00), whereas the PDT time is 7 hours behind UTC (UTC-07:00).

Current time PST (UTC-08:00) PDT (UTC-07:00)
Return value 480 420

For non-DST time zones, the getTimezoneOffset() method always returns the same number of minutes.

Time zone != offset

The getTimezoneOffset() method only gives you the local time zone offset from UTC time and not the actual time zone (e.g. Europe/Berlin).

Using an offset to calculate time zone is not always accurate due to daylight saving rules. Instead, you should use the Intl.DateTimeFormat object.

The Intl.DateTimeFormat object is available in all modern browsers and provides the language-specific date and time formatting methods.

Here is an example that shows how you can get the system's IANA time zone in JavaScript:

const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
console.log(timezone); // Asia/Karachi

✌️ Like this article? Follow me on Twitter and LinkedIn. You can also subscribe to RSS Feed.

You might also like...

Digital Ocean

The simplest cloud platform for developers & teams. Start with a $200 free credit.

Buy me a coffee ☕

If you enjoy reading my articles and want to help me out paying bills, please consider buying me a coffee ($5) or two ($10). I will be highly grateful to you ✌️

Enter the number of coffees below:

✨ Learn to build modern web applications using JavaScript and Spring Boot

I started this blog as a place to share everything I have learned in the last decade. I write about modern JavaScript, Node.js, Spring Boot, core Java, RESTful APIs, and all things web development.

The newsletter is sent every week and includes early access to clear, concise, and easy-to-follow tutorials, and other stuff I think you'd enjoy! No spam ever, unsubscribe at any time.