How to use setUTCDate in JavaScript

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

JavaScript setUTCDate() method

  • setUTCDate() method of date object sets the numeric day of the month for a specified date according to the UTC time.

  • UTC is  The Universal Coordinated Time. it is the set by the World Time Standard.

  • UTC time is the same as GMT time.

Syntax

Date.setUTCDate(dayValue)

  • dayValue is an integer from 1 to 31, representing the day of the month.

  • If dayValue is 0. it will result in the last hour of the previous month
  • If dayValue is -1. it will result in the hour before the last hour of the previous month

Example

In the following example show to setUTCDate() method sets the day of the month, according to UTC.

<!DOCTYPE html>

<html>

<body>

<h3 style="color:Aqua ">JavaScript setUTCDate() Method Example</h3>

<p id="demo">Click to display the date after set the day of the month.</p>

<button onclick="myFunction()">Try it</button>

<script type="text/javascript">

    function myFunction() {

        var d = new Date();

        d.setUTCDate(18);

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

        x.innerHTML ="Changing Date according to UTC : "+ d;

    }

</script>

</body>

</html>

Output1

UTCDate.jpg

Output2

UTCDate 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

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.