JavaScript > Date

GetUTCSeconds() Method in JavaScript

How to return the seconds, according to UTC time in JavaScript?

By using getUTCSeconds() we can return the seconds according to UTC.

<p>Click the below button to return the seconds as per the UTC.</p>
<input type="button" value="Click" onclick="myTime()" />
<p id="myId"></p>

    function myTime() {
        var a = new Date();        //* Returns the Time & Date as per the UTC*//
        var r = a.getUTCSeconds(); //* Returns the seconds from the above returned time *//
        document.getElementById("myId").innerHTML = r;

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 seconds as per the UTC, for that we are using getUTCSeconds(). In the <script> block variable a returns the time and date as per the UTC, from that getUTCSeconds() return the seconds from the time zone. Onclick of the button "Click" in the HTML code fires the function myDate() in the <script> block at the same time getUTCSeconds() return the seconds as output according to UTC. 


NOTE: This post is posted on {Thu Oct 15 2015 13:14:59 GMT+0530 (India Standard Time)}, from this we return the seconds as main output by using getSeconds().

 Views: 3216 | Post Order: 124

Write for us

Hosting Recommendations