How To Get Current Month Number in JavaScript?

Jul 26, 2021 . Admin

Hello Friends, Now let's see example of how to use javascript get current month number example. We will use how to use if get current month number in javascript. Here you will learn how to use javascript get current month number. This is a short guide on get current month number. Let's get started with how to get current month number in javascript. Here i will give you many example how you can check javascript get current month number. Example: 1
<!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:
6
Example: 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....

#Javascript