JavaScript Date getTimezoneOffset() Method - GeeksforGeeks

19 Oct, 2021
Below is the example of Date getTimezoneOffset() method.  
Example:  
javascript
<script>     // If nothing is in parameter it takes    // the current date while creating Date object    var date = new Date();         // Extracting the time difference between    // UTC and local time    var diff = date.getTimezoneOffset();        //Printing on console   document.write(diff); </script>
Output:  
-330
The date.getTimezoneOffset() method is used to return the time difference between Universal Coordinated Time (UTC) and local time, in minutes. If your time zone is GMT+5, -300 (60*5) minutes will be returned. Daylight savings prevent this value from being constant.Syntax:  
date.getTimezoneOffset()
Parameter: This method does not accept any parameter. Return Values: It returns a number representing the time difference between UTC and Local Time in minutes.More codes for the above method are as follows:Program 1: The date of the month should lie in between 1 to 31 because none of the months have a date greater than 31 that is why it returns NaN i.e, not a number because the date for the month does not exist.  
javascript
<script>     // Taking the date while creating Date object    var date=new Date('Aug 32 2018 5:30');         // Extracting the timedifference between    // UTC and local time    var n=date.getTimezoneOffset();    document.write(n) </script>
Output:  
NaN
Program 2: In this example we will leave the new Date blank to get the time difference between UTC and local time by a trigger.  
javascript
<!DOCTYPE html><html>    <head>        <title>            JavaScript Date geTimexoneOffset() Method        </title>    </head>    <body style="text-align: center;">        <h1 style="color: green;">GeeksforGeeks</h1>        <b>JavaScript Date geTimexoneOffset() Method</b>        <br />        <br />        <button onclick="gfg()">Click me</button>         <script>            function gfg() {                // If nothing is in parameter it takes                // the current date while creating                // Date object                var date = new Date("June 29 2020 10:30");                 // Extracting the time difference between                // UTC and local time                var diff = date.getTimezoneOffset();                 //Printing on console                document.write(diff);            }        </script>    </body></html>
Output:  
Note: The Universal Coordinated Time (UTC) is the time set by the World Time Standard. UTC is the same as GMT time.Supported Browsers: The browsers supported by JavaScript Date getTimezoneOffset() method are listed below:  
Google Chrome 1 and above
Edge 12 and above
Firefox 1 and above
Internet Explorer 5 and above
Opera 3 and above
Safari 1 and above
 
ysachin2314
javascript-date
JavaScript-Methods
JavaScript
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Remove elements from a JavaScript Array
Convert a string to an integer in JavaScript
Difference between var, let and const keywords in JavaScript
Differences between Functional Components and Class Components in React
How to append HTML code to a div using JavaScript ?
Remove elements from a JavaScript Array
Installation of Node.js on Linux
Convert a string to an integer in JavaScript
How to fetch data from an API in ReactJS ?
Difference between var, let and const keywords in JavaScript