JavaScript getTimezoneOffset() | Find Difference between UTC and Local Time

The JavaScript getTimezoneOffset() method is used when we need to find the difference between UTC (same as GMT) and local time. For example:

HTML with JavaScript Code
<!DOCTYPE html>
<html>
<body>
   
   <p id="xyz"></p>

   <script>
      const d = new Date();
      let timeDifference = d.getTimezoneOffset();
      document.getElementById("xyz").innerHTML = timeDifference;
   </script>

</body>
</html>
Output

JavaScript getTimezoneOffset() Syntax

The syntax of getTimezoneOffset() method in JavaScript is:

x.getTimezoneOffset()

where x must be an object of the Date() constructor.

The getTimezoneOffset() returns a number which will be the time difference between the UTC and the Local time in minutes.

Please note: To display date in format dd-mm-yyyy, refer to its separate example.

Please note: To display time in format hh:mm:ss, refer to its separate example.

Please note: To display time in format hh:mm:ss AM/PM, refer to its separate example.

JavaScript Online Test


« Previous Tutorial Next Tutorial »