JavaScript setUTCMonth() Method
Example
Set the month to 4 (April):
var d = new Date();
d.setUTCMonth(4);
d Result output:
Try it »
Definition and Usage
The setUTCMonth() method is used to set the month according to Universal Time (UTC).
Note: 0 (January) ~ 11 (December)
This method can be used to set a certain day of the month.
**Note:** Coordinated Universal Time, also known as Universal Time, Universal Standard Time, or International Coordinated Time, abbreviated as UTC (Universal Coordinated Time).
Browser support





All major browsers support the setUTCMonth() method.
Syntax
Date
.setUTCMonth(
month
,
day
)
Parameter value
| Parameters | Description |
|---|---|
| month | Required. The value to set for the month field of dateObject, expressed in universal time.
This parameter is an integer between 0 (January) and 11 (December): |
An integer between 1 and 31, used as the day field of date Object, expressed in universal time.
- 0 is the last hour of the previous month.
- -1 is the hour before the last hour of the previous month.
If the current month has 31 days:
- 32 is the first day of the next month.
If the current month has 30 days:
- 32 is the second day of the next month.
Return Value
| Type | Description |
|---|---|
| Number | The milliseconds representation of the adjusted date. |
Technical Details
| JavaScript version: | 1.3 |
|---|
More examples
Example
The following example sets the month to 4 (April) and the date to the 20th:
var d = new Date();
d.setUTCMonth(4,20);
d The output according to local time will be:
Try it »
Example
Set the date to the last day of the previous month:
var d = new Date();
d.setUTCMonth(d.getUTCMonth(),0);
d The output according to local time will be:
Try it »
JavaScript Date object