getMonth()  Date  instance method JS Home  <<  JS Reference  <<  Date  <<  getMonth()

Description

Returns the locale specific month of the year (0-11) for the specified date.
0 = January, 1 = February etc.

Syntax

Signature Description
aDate.getMonth()Returns the locale specific month of the year (0-11) for the specified date. 0 = January, 1 = February etc.

Parameters

None.

Examples

The code below shows examples of the getMonth() method of Date.



// Create a Date instance for the current date and time.
var todaysDate = new Date();
alert(todaysDate);

// Get month as a number.
alert(todaysDate.getMonth() + ' = Month as a number');

// Use an array to display the month as a string.
var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 
              'August', 'September', 'October', 'November', 'December']; 
alert(months[todaysDate.getMonth()] + ' = Month as a string');

Press the button below to action the above code:

Related Tutorials

JavaScript Intermediate Tutorials - Lesson 2 - Dates and Times