Javascript Date setUTCDate(date)

Introduction

Javascript Date setUTCDate(date) sets the day of the month for the UTC date.

dateObj.setUTCDate(dayValue)

Parameters

  • dayValue - An integer from 1 to 31, representing the day of the month.

Return value

The number of milliseconds between 1 January 1970 00:00:00 UTC and the updated date.

If a parameter is outside of the expected range, setUTCDate() updates the date accordingly.

For example, if we use 40 for dayValue, and the month stored in the Date object is June, the day will be changed to 10 and the month will be incremented to July.

If the date is greater than the number of days in the month, the month value also gets increased.

var d = new Date();
console.log(d);//from w  w  w .j a va 2s . c om
d.setUTCDate(20);
console.log(d);

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

var d = new Date();
d.setUTCDate(0);//from   www  .j a v a2  s . co m
console.log(d);

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

var d = new Date("July 21, 2010 01:15:00");
d.setUTCDate(15);//w w  w .  j  ava2  s.c  o  m
console.log(d);



PreviousNext

Related