Javascript Date setUTCMonth(month)

Introduction

Javascript Date setUTCMonth(month) sets the month of the UTC date, which is any number 0 or greater. Numbers greater than 11 add years.

dateObj.setUTCMonth(monthValue[, dayValue])

Parameters

  • monthValue - An integer between 0 and 11, representing the months January through December.
  • dayValue - Optional. 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, setUTCMonth() updates the date accordingly.

For example, if you use 15 for monthValue, the year will be incremented by 1, and 3 will be used for month.

var d = new Date();
console.log(d);/*ww  w . j a  v  a 2s  .c  o m*/
d.setUTCMonth(11);
console.log(d);

Set the month to 4 (May) and the day to the 20th:

var d = new Date();
d.setUTCMonth(4, 20);/* w w w.j av  a2s.c  om*/
console.log(d);

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

var d = new Date();
d.setUTCMonth(d.getUTCMonth(), 0);/*from   www .  java  2s  .co m*/
console.log(d);



PreviousNext

Related