How To Get Current Month Name in JavaScript?

Jul 27, 2021 . Admin

Hello Friends, Now let's see example of how to use javascript get current month name example. We will use how to use if get current month name in javascript. Here you will learn how to use javascript get current month name. This is a short guide on get current month name. Let's get started with how to get current month name in javascript. Here i will give you many example how you can check javascript get current month name. Example: 1
<!DOCTYPE html>
<html>
    <head>
        <title>How to get current month name in javascript?</title>
        <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
    </head>
    <body class="bg-dark">
        <div class="container mt-5">
            <div class="row">
                <div class="col-md-6 offset-md-3">
                    <div class="card">
                        <div class="card-header">
                            <h5>How to get current month name in javascript</h5>
                        </div>
                        <div class="card-body">
                            <p>Click the button to display the name of this month.</p>
                            <button onclick="cmp()" class="btn btn-primary mb-2">Check</button>
                            <p id="emp"></p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <script>
            function cmp() {
                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 a = month[d.getMonth()];
                document.getElementById("emp").innerHTML = a;
            }
        </script>
    </body>
</html>
Output:
July
Example: 2
<!DOCTYPE html>
<html>
    <head>
        <title>How to get current month name in javascript?</title>
        <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
    </head>
    <body>
        <script>
            const monthNm = ["January", "February", "March", "April", "May", "June",
                "July", "August", "September", "October", "November", "December"
            ];
            const b = new Date();
            document.write("The current month is " + monthNm[b.getMonth()]);
        </script>
    </body>
</html>
Output:
July

It will help you....

#Javascript