Home >>JavaScript Date Object Methods >JavaScript setUTCMonth() Method
JavaScript setUTCMonth() method is used to set the month according to the universal time (UTC). It returns an integer as result having a value between 0 to 11 where 0 is for January, 1 is for February, and so on.
Syntax:Date.setUTCMonth(month, day)
Parameter | Description |
---|---|
month | This is a required parameter. It defines an integer representing the month. |
day | This is an optional parameter. It defines an integer representing the day of month. |
Method | Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
setUTCMonth() | Yes | Yes | Yes | Yes | Yes |
<html> <body> <p>Click the button to see the Output.</p> <button onclick="myFunction()">Try it</button> <p id="demo"></p> <script> function myFunction() { var d = new Date(); d.setUTCMonth(4); document.getElementById("demo").innerHTML = d; } </script> </body> </html>
Click the button to see the Output.
<html> <body> <p>Click the button to see the Output.</p> <button onclick="myFunction1()">Try it</button> <p id="demo1"></p> <script> function myFunction1() { var d = new Date(); d.setUTCMonth(5, 10); document.getElementById("demo1").innerHTML = d; } </script> </body> </html>
Click the button to see the Output.