JavaScript | date.getTimezoneOffset() with Examples
The date.getTimezoneOffset() is an inbuilt function of javaScript which is used to return the time difference between Universal Co-ordinated 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 a constant.
Syntax:
date.getTimezoneOffset()
In the above syntax, date is a valid Date object created by using Date() constructor.
Parameter: It does not accept any parameter.
Return Values: It returns a number representing the time difference between UTC and Local Time in minutes.
Example 1:
<script> // If nothing is in parameter it takes // the current date while creating Date object var date = new Date(); // Extracting the timedifference between // UTC and local time var diff = date.getTimezoneOffset(); //Printing on console document.write(diff); </script> |
Output:
-330
Example 2:
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.
<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
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() are listed below:
- Google Chrome
- Internet Explorer
- Firefox
- Opera
- Safari
Recommended Posts:
- JavaScript | _.reduceRight() with Examples
- JavaScript | weakSet.has() with Examples
- JavaScript | typedArray.name with Examples
- Javascript | _.reduce() with Examples
- JavaScript | weakMap.has() with Examples
- JavaScript | weakMap.set() with Examples
- JavaScript | weakSet.add() with Examples
- JavaScript | typedArray.from() with Examples
- JavaScript | parseFloat() with Examples
- JavaScript | typedArray.every() with Examples
- JavaScript | typedArray.of() with Examples
- JavaScript | addEventListener() with Examples
- JavaScript | getPrototypeOf() with Examples
- JavaScript | typedArray.map() with Examples
- JavaScript | parseInt() with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



