JavaScript getMonth() Method

You are Here:

JavaScript getMonth() Method

The getMonth() method returns an integer number, between 0 (January) and 11 (December), representing the month in the given date according to local time.

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <p>Click the button to display current month.</p> <button onclick="myFunction()">Display Month</button> <p id="point"></p> <script> function myFunction() { var d = new Date(); var n = d.getMonth(); document.getElementById("point").innerHTML = n; } </script> </body> </html>

Syntax

Date.getMonth()

Return Value

ValueExplanation
NumberAn integer number, between 0 (January) and 11 (December), representing the month in the given date according to local time.

Get Month Name from Current Date

In the following example, we will get the name of the current month from a current date.

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <p>Click the button to display current month.</p> <button onclick="myFunction()">Display Month</button> <p id="point"></p> <script> var arr = []; arr[0] = "January"; arr[1] = "February"; arr[2] = "March"; arr[3] = "April"; arr[4] = "May"; arr[5] = "June"; arr[6] = "July"; arr[7] = "August"; arr[8] = "September"; arr[9] = "October"; arr[10] = "November"; arr[11] = "December"; function myFunction() { var d = new Date(); var n = d.getMonth(); document.getElementById("point").innerHTML = arr[n]; } </script> </body> </html>

Get Month from Specific Date

In the following example, we will get the month from a specific date.

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <p>Click the button to display month of the given date.</p> <button onclick="myFunction()">Display Month</button> <p id="point"></p> <script> function myFunction() { var d = new Date("May 19, 1995 02:30:25"); var n = d.getMonth(); document.getElementById("point").innerHTML = n; } </script> </body> </html>

Get Month Name from Specific Date

In the following example, we will get the name of the month from a specific date.

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <p>Click the button to display month of the given date.</p> <button onclick="myFunction()">Display Month</button> <p id="point"></p> <script> var arr = []; arr[0] = "January"; arr[1] = "February"; arr[2] = "March"; arr[3] = "April"; arr[4] = "May"; arr[5] = "June"; arr[6] = "July"; arr[7] = "August"; arr[8] = "September"; arr[9] = "October"; arr[10] = "November"; arr[11] = "December"; function myFunction(){ var d = new Date("May 19, 1995 02:30:25"); var n = d.getMonth(); document.getElementById("point").innerHTML = arr[n]; } </script> </body> </html>

Reminder

Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in JavaScript.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author