JavaScript & jQuery Tutorials

JS Home Right Arrow JS Reference Right Arrow Date Right Arrow getMonth()

getMonth()  Date  instance method

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




  

go to home page Homepage go to top of page Top