JavaScript > Date

GetTimezoneOffset() Method in JavaScript

How to return the time zone difference between UTC and Local time in JavaScript?


By using getTimexoneOffset() method we can return the timezone difference between UTC and Local time.

<p>Click the below button to display the time difference between UTF and Local time..</p>
<input type="button" value="Click" onclick="myDate()" />
<p id="myId"></p>

<script>
    function myDate() {
        var a = new Date();
        var r = a.getTimezoneOffset();
        document.getElementById("myId").innerHTML = R;
    }
</script>

In the above code snippet we have given Id as "myId"to the second <p> element in the HTML code. There is a function myDate() in the<script>block which is connected to the Onclick of the HTML button. The document.getElementById("myId")returns the element that has Id"id=myID" in the HTML page. We need to return the timezone difference between UTC and Local time for that we are using getTimezoneOffset(). Onclick of the button "Click" in the HTML code fires the function myDate() in the <script> block at the same time getTimezoneOffset() return the timezone difference between UTC and local time as output.

OUTPUT

 Views: 3527 | Post Order: 108



Write for us






Hosting Recommendations