# How to get current time zone in JavaScript

By Atta Ur Rehman Shah (https://attacomsian.com/about). Published Jun 13, 2021, updated Sep 10, 2022. Topics: JavaScript.
Canonical URL: https://attacomsian.com/blog/javascript-current-timezone

> A quick article to learn how to retrieve the browser's time zone using 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:

```javascript
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](https://caniuse.com/?search=intl.datetimeformat) 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](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) in JavaScript:

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