Date object representing the date from which you want to get the month value.
Simple example code.
<!DOCTYPE html> <html> <body> <script> var currentDate = new Date(); var currentMonth = currentDate.getMonth(); console.log("Current month: " + currentMonth); </script> </body> </html>
Note that the
getMonth() method is zero-indexed, meaning January is represented by 0, February by 1, and so on. If you want to display the month with the correct index (1 to 12), you can add 1 to the result returned by
var currentDate = new Date(); var currentMonth = currentDate.getMonth() + 1; // adds 1 on current date console.log("Current month: " + currentMonth);
Do comment if you have any doubts or suggestions on this Js date method topic.
Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version