How To Get Current Month Number in JavaScript?
Jul 26, 2021 . Admin

<!DOCTYPE html> <html> <head> <title>How to get current month number 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 number in javascript</h5> </div> <div class="card-body"> <p>Click the button to display the number that represent this month.</p> <button onclick="cmp()" class="btn btn-primary mb-2">Check</button> <p id="emp"></p> <p><strong>Note:</strong> 0=January, 1=February.</p> </div> </div> </div> </div> </div> <script> function cmp() { var b = new Date(); var d = b.getMonth(); document.getElementById("emp").innerHTML = d; } </script> </body> </html>Output:
6Example: 2
<!DOCTYPE html> <html> <head> <title>How to get current month number in javascript?</title> </head> <body> <script type = "text/javascript"> var today = new Date(); var monthNm = today.getMonth(); alert(monthNm); </script> </body> </html>Output:
6
It will help you....