Date setUTCDate() Method - Javascript Date

Javascript examples for Date:setUTCDate

Description

The setUTCDate() method sets the day of the month, according to the UTC time.

UTC time is the same as GMT time.

Syntax

date.setUTCDate(day)

Parameter Values

Parameter Description
day Required. An integer representing the day of a month.

day expected values are 1-31, but other values are allowed:

  • 0 sets the last hour of the previous month
  • -1 sets the hour before the last hour of the previous month
  • If the month has 31 days: 32 sets the first day of the next month
  • If the month has 30 days: 32 sets the second day of the next month

Return Value:

A Number, representing the number of milliseconds between the date object and midnight January 1 1970

The following code shows how to Set the day of the month, according to UTC:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {/*from   w ww. j  a v  a  2 s .c om*/
    var d = new Date("July 21, 2020 01:15:00");
    d.setUTCDate(15);
    document.getElementById("demo").innerHTML=d;
}
</script>

</body>
</html>

Related Tutorials