The setUTCMonth() method sets the month ranged from 0 to 11, according to universal time.
The setUTCMonth() method sets the month ranged from 0 to 11, according to universal time.
January is 0, February is 1, and so on.
You can use this method to set the day of the month.
UTC time is the same as GMT time.
Date.setUTCMonth(month,day)
Parameter | Require | Description |
---|---|---|
month | Required. | An integer representing the month |
day | Optional. | An integer representing the day of month |
For the month value, the expected values are 0-11, but other values are allowed:
For the day value, the expected values are 1-31, but other values are allowed:
A Number, representing the number of milliseconds between the date object and midnight January 1 1970
Set the month to 4 (May):
//display the date after changing the month. var d = new Date(); d.setUTCMonth(4);/*from w ww . j a va2 s . co m*/ console.log(d); //Set the month to 4 (May) and the day to the 20th: //display the date after changing the month and day. var d = new Date(); d.setUTCMonth(4, 20); console.log(d); //Set the date to be the last day of last month: //display the date after setting the date to be the last day of last month. var d = new Date(); d.setUTCMonth(d.getUTCMonth(), 0); console.log(d);