Javascript - Date setUTCDate() Method

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

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 Require Description
day Required. An integer representing the day of a month.

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

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

Return

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

Example

Set the day of the month, according to UTC:

Demo

//display the date after changing the day of the month.
var d = new Date();
d.setUTCDate(15);/* w w  w  . j  a v  a2 s. c  o  m*/
console.log(d);

//Set the day of the month to be the last day of the previous month:

//display the date after changing it to be the last day of the previous month.
var d = new Date();
d.setUTCDate(0);
console.log(d);

//Set the day of the month, to a specified date:

//display a specified date after changing the day of the month.
var d = new Date("July 21, 2010 01:15:00");
d.setUTCDate(15);
console.log(d);

Result