JavaScript > Date

GetUTCDay() Method in JavaScript

How to return the day of the week, according to UTC in JavaScript?


By using getUTCDay() we can return the day of the week, according to UTC.

NOTE: UTC is nothing but the Universal Time Cordinated which used across the world since 1972, which is useful for synchronizing the time as per the internet networks.

<p>Click the below button to display the day of the week as per the UTC.</p>
<input type="button" value="Click" onclick="myDate()" />
<p id="myId"></p>

<script>
    function myDate() {
        var a = new Date();
        var r = a.getUTCDay();
        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 day of the week, according to UTC, for that we are using getUTCDay(). Onclick of the button "Click" in the HTML code fires the function myDate() in the <script> block at the same time getUTCDay() return the day of the week according to UTC as a output.

OUTPUT

NOTE: In this case 0=Sunday, 1=Monday, 2=Tuesday.....................6=Saturday.

 Views: 3956 | Post Order: 110



Write for us






Hosting Recommendations