JavaScript Date setUTCMonth() Method
- Previous Page setUTCMinutes()
- Next Page setUTCSeconds()
- Go to the Previous Level JavaScript Date Reference Manual
Definition and Usage
setUTCMonth()
The method sets the month according to the UTC (from 0 to 11).
Note:January is 0, February is 1, and so on.
This method can also be used to set the date in the month.
Tip:Coordinated Universal Time (UTC) is the time set by the world time standard.
Note:UTC time is the same as GMT time (Greenwich Mean Time).
Example
Example 1
Set the month to 4 (May):
var d = new Date(); d.setUTCMonth(4);
Example 2
Set the month to 4 (May) and the date to 20th:
var d = new Date(); d.setUTCMonth(4, 20);
Example 3
Set the date to the last day of the previous month:
var d = new Date(); d.setUTCMonth(d.getUTCMonth(), 0);
Syntax
Date.setUTCMonth(month, day)
Parameter Value
Parameter | Description |
---|---|
month |
Required. An integer representing the month. Expected value is 0-11, but other values are allowed:
|
day |
Optional. An integer representing the day of the month. Expected value is 1-31, but other values are allowed:
If a month has 31 days:
If a month has 30 days:
|
Technical Details
Return Value: | A numerical value representing the number of milliseconds between the date object and midnight of January 1, 1970. |
---|---|
JavaScript Version: | ECMAScript 1 |
Browser Support
Method | Chrome | IE | Firefox | Safari | Opera |
---|---|---|---|---|---|
setUTCMonth() | Support | Support | Support | Support | Support |
Related Pages
Tutorial:JavaScript Date
Tutorial:JavaScript Date Format
Tutorial:JavaScript Date Setting Methods
- Previous Page setUTCMinutes()
- Next Page setUTCSeconds()
- Go to the Previous Level JavaScript Date Reference Manual