JavaScript getTimezoneOffset() Method

You are Here:

JavaScript getTimezoneOffset() Method

The getTimezoneOffset() method returns a number representing the time-zone offset, in minutes, from the date based on current host system settings to UTC.

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <p>Click the button to display the timedifference between UTC and local time.</p> <button onclick="myFunction()">Display Time Difference</button> <p id="point"></p> <script> function myFunction(){ var d = new Date(); var n = d.getTimezoneOffset(); document.getElementById("point").innerHTML = n; } </script> </body> </html>

Syntax

Date.getTimezoneOffset()

Return Value

ValueExplanation
NumberReturns a number representing the time-zone offset, in minutes, from the date based on current host system settings to UTC.

Check Manually

In the following example, we will manually differentiate the time difference between UTC and local time.

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <p>Click the button to display the timedifference between UTC and local time.</p> <button onclick="myFunction()">Display Time Difference</button> <p id="point"></p> <script> // verifying getTimezoneOffset(). function myFunction(){ // local date var d = new Date(); var m = d.getFullYear(); var n = d.getMonth(); var o = d.getDate(); var p = d.getHours(); var q = d.getMinutes(); var r = d.getSeconds(); var s = d.getMilliseconds(); //UTC date var utcDate = Date.UTC(m, n, o, p, q, r, s); //convert milliseconds to minutes d = d / (60 * 1000); utcDate = utcDate / (60 * 1000); // result var result = d - utcDate; document.getElementById("point").innerHTML = result; } </script> </body> </html>

Reminder

Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in JavaScript.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author