How To Get Current Month Name in JavaScript?
Jul 27, 2021 . Admin

<!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:
JulyExample: 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....