Home >>JavaScript Date Object Methods >JavaScript getMonth() Method
JavaScript getMonth() method is used to return the month for the given input date according to the local time. It returns an integer value between 0 to 11 where 0 is for January, 1 is for February, and so on.
Syntax:Date.getMonth()
Method | Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
getMonth() | 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(); var n = d.getMonth(); document.getElementById("demo").innerHTML = n; } </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 month = new Array(); month[0] = "January"; month[1] = "February"; month[2] = "March"; month[3] = "April"; month[4] = "May"; month[5] = "June"; month[6] = "July"; month[7] = "August"; month[8] = "September"; month[9] = "October"; month[10] = "November"; month[11] = "December"; var d = new Date(); var n = month[d.getMonth()]; document.getElementById("demo1").innerHTML = n; } </script> </body> </html>
Click the button to see the Output.