Latest web development tutorials

JavaScript getMonth () method

Date Object Reference JavaScript Date Object

Examples

Returns the month:

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

n output:


try it"

Definition and Usage

getMonth () method returns the month number. The return value is an integer from 0 (January) to 11 (December).

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


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support getMonth () method


grammar

Date .getMonth ()

Return Value

Types of description
Number The return value is an integer from 0 (January) to 11 (December).

technical details

JavaScript version: 1.0


More examples

Examples

Now we'll 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()];

Examples of the above output:


try it"


Date Object Reference JavaScript Date Object