Friday, October 24, 2025
HomeLanguagesJavascriptHow to get the client timezone offset in JavaScript?

How to get the client timezone offset in JavaScript?

The client’s timezone offset could be detected by using the Date object’s getTimezoneOffset() method.

The getTimezoneOffset() method returns the time difference between UTC time and local time, that is the time offset, in minutes. This offset is changed by dividing by 60 and negating the result.

Note: The getTimezoneOffset() does not account for Daylight Savings, therefore this value may not be constant.

Syntax:

offset = new Date().getTimezoneOffset()

Example:




<!DOCTYPE html>
<html>
      
<head>
    <title>
        How to get the client timezone
        offset in JavaScript?
    </title>
</head>
  
<body>
    <h1 style="color: green">
        GeeksForGeeks
    </h1>
      
    <b>
        How to get the client timezone
        offset in JavaScript?
    </b>
      
    <p>
        Click on the button to get
        the timezone offset
    </p>
      
    <p>Output: <span class="output"></span></p>
      
    <button onclick="getTimezone()">
        Get timezone
    </button>
      
    <!-- Script to get the client timezone -->
    <script type="text/javascript">
        function getTimezone() {
            offset = new Date().getTimezoneOffset();
            formatted = -(offset / 60);
            document.querySelector('.output').textContent
                    = formatted;
        }
    </script>
</body>
  
</html>                    


Output:

  • Before clicking the button: before-click
  • After clicking the button: after-click
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS