How to use getTimezoneOffset in JavaScript

In this article, I will explain use of getTimezoneOffset() method in JavaScript date object.
  • 2924

JavaScript date getTimezoneOffset() method

  • getTimezoneOffset() method of date object returns the time difference between UTC time and local time, in minutes.
  • In getTimezoneOffset() method, The returned value is not a constant because it's using Daylight Saving Time.




In the following example show to how the getTimezoneOffset() method can be used.

<!DOCTYPE html>



<h3 style="color:green">JavaScript getTimezoneOffset() Method Example</h3>

<p id="demo">Click for display the timedifference between UTC and local time</p>

<button onclick="myFunction()">Click On</button>

<script type="text/javascript">

    function myFunction() {

        var d = new Date();

        var x = document.getElementById("demo");

        x.innerHTML = d.getTimezoneOffset();

        document.write("Diffrence between UTC and local time is: " + d.getTimezoneOffset());






gettimezone 1.jpg


gettimezone 2.jpg

You may also want to read these related articles here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here


More Articles

© 2020 DotNetHeaven. All rights reserved.