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());