Friday, September 5, 2025
HomeLanguagesJavascriptHow to get the month name from Date using JavaScript ?

How to get the month name from Date using JavaScript ?

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 ranging 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




<body style="text-align:center;">
    <h2 style="color:green">
        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>


Output:

get the month name from Date using JavaScript

get the month name from Date using JavaScript

RELATED ARTICLES

Most Popular

Dominic
32269 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6638 POSTS0 COMMENTS
Nicole Veronica
11802 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11867 POSTS0 COMMENTS
Shaida Kate Naidoo
6752 POSTS0 COMMENTS
Ted Musemwa
7028 POSTS0 COMMENTS
Thapelo Manthata
6704 POSTS0 COMMENTS
Umr Jansen
6721 POSTS0 COMMENTS