JavaScript getMonth () method
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
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()];
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"