The getMonth method returns the month of the point in time stored in a Date object. The value returned by this method is an integer number from 0 to 11, zero being January and eleven being December.
Syntax
myDate.getMonth()
With myDate being an object based on the Date object.
Instead of being instantiated from a class, in JavaScript objects are created by replicating other objects. This paradigm is called Prototype-based programming.
Example
The following code uses the getMonth method to return the month of the current date:
<script type="text/javascript">
function getMonthName(monthNumber)
{
var monthNames = new Array("January", "February", "March", "April", "May", "June", "July","August","September", "October", "November", "December");
return monthNames[monthNumber];
}
var currentDate = new Date();
var monthNumber = currentDate.getMonth();
var nameOfTheMonth = getMonthName(monthNumber);
document.write("The number of the current month is " + monthNumber + ", which means it is " + nameOfTheMonth + ".");
</script>
function getMonthName(monthNumber)
{
var monthNames = new Array("January", "February", "March", "April", "May", "June", "July","August","September", "October", "November", "December");
return monthNames[monthNumber];
}
var currentDate = new Date();
var monthNumber = currentDate.getMonth();
var nameOfTheMonth = getMonthName(monthNumber);
document.write("The number of the current month is " + monthNumber + ", which means it is " + nameOfTheMonth + ".");
</script>
Technical Details
The getMonth method belongs to the Date object, it is available since the version 1.0 of JavaScript, and it is supported in all major browsers.
JavaScript Manual >> Date Object >> getMonth Method