JavaScript Date setUTCMonth() method
The JavaScript date setUTCMonth() method is used to set the integer value that represents the month in the specified date on the basis of universal time. The setUTCMonth() method value starts with 0 that represents January.
Syntax
The setUTCMonth() method is represented by the following syntax:
Parameter
monthValue – It represents an integer value between 0 and 11 specifying the month.
dayValue – It is optional. It represents an integer value between 1 and 31 specifying the day of the month.
JavaScript Date setUTCMonth() method example
Here, we will understand setUTCMonth() method through various examples.
Example 1
Let’s see an example to print current and updated month.
Output:
Current month : 8 Updated month : 9
Example 2
Let’s see an example to update the month of the given date.
Output:
11
Example 3
In this example, we will also specify the particular day with the month.
Output:
Updated month : 12