JavaScript > Date

SetUTCDate() Method in JavaScript

How to set the day of the month according to UTC time in JavaScript?

By using setUTCDate() we can set the day of the month according to UTC time.

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

    function myDate() {
        var a = new Date();
        document.getElementById("myId").innerHTML = a;

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 set the day of the month according to UTC, for that we are using setUTCDate() method and we have given value "10" to this method, so in the output setUTCDate() method returns 10th day of the month. Onclick of the button "Click" in the HTML code fires the function myDate() in the <script> block, at the same setUTCDate() method sets day of the month as per the given value and gives the output.


 Views: 3548 | Post Order: 126

Write for us

Hosting Recommendations