The Wayback Machine - https://web.archive.org/web/20240213201436/https://www.geeksforgeeks.org/how-to-get-the-client-timezone-offset-in-javascript/
Open In App
Related Articles

How to get the client timezone offset in JavaScript?

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report
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

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!


Last Updated : 30 Apr, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials