Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

JavaScript getMonth() Method

JavaScript getMonth() Method

Date Object Reference JavaScript Date object

Example

Return the month:

var d = new Date();

var n = d.getMonth();

n Output result:

Try it »


Definition and Usage

The getMonth() method returns a number representing the month. The return value is an integer between 0 (January) and 11 (December).

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


Browser support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the getMonth() method.


Syntax

Date

.getMonth()

Return Value

Type Description
Number The return value is an integer between 0 (January) and 11 (December).

Technical Details

JavaScript version: 1.0

More examples

Example

Now we will create an array to output the name of the month instead of a 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()];

The example above produces the following output:

Try it »


Date Object Reference JavaScript Date object