JavaScript Date getMonth() Method

Definition and Usage

getMonth() The method returns the month (from 0 to 11) of the specified date according to local time.

Note:January is 0, February is 1, and so on.

Example

Example 1

Returns the month:

var d = new Date();
var n = d.getMonth();

Try It Yourself

Example 2

Returns the name of the month (not just the number):

var d = new Date();
var month = new Array();
month[0] = "January";
month[1] = "February";
month[2] = "March";
month[3] = "April";
month[4] = "May";
month[5] = "June";
month[6] = "July";
month[7] = "August";
month[8] = "September";
month[9] = "October";
month[10] = "November";
month[11] = "December";
var n = month[d.getMonth()];

Try It Yourself

Syntax

Date.getMonth()

Parameters

No parameters.

Technical Details

Return Value: A number, from 0 to 11, representing the month.
JavaScript Version: ECMAScript 1

Browser Support

Method Chrome IE Firefox Safari Opera
getMonth() Support Support Support Support Support

Related Pages

Tutorial:JavaScript Date

Tutorial:JavaScript Date Format

Tutorial:JavaScript Object Constructor