Timezone offset is the time difference in hours or minutes between the Coordinated Universal Time (UTC) and a given time zone.
Code Snippet: In the below code snippet, date.getTimezoneOffset() method will return the timezone difference in minutes, between the UTC and the local time. This will be stored in offset variable.
Example: On clicking the “submit” button, showOffset() method is called which stores the value of timezone offset in offset variable. Then result text is inserted in the empty p tag.
- Before Clicking the button:
- After Clicking the button:
Note: The method returns your local timezone offset in minutes and not the timezone offset of the “date” object.
// Output will be your local timezone offset // It does not depend on date object. var date = new Date('August 21, 2000 18:02:25 GMT+05:00'); console.log(date.getTimezoneOffset());
- How to create a date with a set timezone without using a string representation?
- How to generate a drop down list of timezone using PHP ?
- How to set the offset property for ScrollSpy in Bootstrap ?
- How to get rid of an element offset using CSS ?
- jQuery | offset() with Examples
- CSS | outline-offset Property
- What is the difference between position() and offset() in jQuery ?
- How to avoid undefined offset error in PHP ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.