The purpose of this article is to get the month name from a particular date using JavaScript getMonth() method. This method is used to fetch the month(0 to 11) from the given Date object. It returns an integer value ranges from (0 to 11) Zero (0) means January, 1 means February, and so on, till 11 means December.
Syntax:
DateObj.getMonth()
Example: The below code is used to display the current month belonging to the particular Date.
HTML
<!DOCTYPE html> <html> <body style="text-align:center;"> <h2> GeeksForGeeks </h2> <h2> How to get month name from Date using Javascript? </h2> <button onclick="myFunction()"> Click Me! </button> <h3 id="demoID" style="color:green;"> </h3> <script> function myFunction() { // initializing an array const months = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ]; const d = new Date(); document.getElementById( "demoID").innerHTML = "The current month is " + months[d.getMonth()]; } </script> </body> </html> |
Output:
-
Before clicking on button:
-
After clicking on button:
Supported Browsers:
- Google Chrome
- Internet Explorer
- Firefox
- Opera
- Safari
Recommended Posts:
- How to validate if input date (end date) in input field must be after a given date (start date) using express-validator ?
- How to validate if input date (start date) in input field must be before a given date (end date) using express-validator ?
- How to get the first and last date of current month using JavaScript ?
- How to get Month and Date of JavaScript in two digit format ?
- How to get last day of a month from date in PHP ?
- How to get the day and month of a year using JavaScript ?
- How to get the number of days in a specified month using JavaScript ?
- How to check the input date is equal to today's date or not using JavaScript ?
- How to convert UTC date time into local date time using JavaScript ?
- HTML | DOM Input Month name Property
- How to convert number to month name in PHP?
- How to get the function name from within that function using JavaScript ?
- How to get the file name from full path using JavaScript ?
- How to get currently running function name using JavaScript ?
- How to get the file name from page URL using JavaScript ?
- How to get the first key name of a JavaScript object ?
- HTML | DOM Input Date name Property
- How to get current formatted date dd/mm/yyyy in JavaScript ?
- JavaScript | Get Date Methods
- How to get the current date in JavaScript ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


