The date.getMonth() method is used to fetch the month(0 to 11) from the given Date object.
Parameter: This function does not accept any parameter.
Return Value: It returns the Month for the given Date object. The month is an integer value ranging from 0 to 11. Zero (0) means January, 1 means February, and so on till 11 means December.
Below is an example of Date getMonth() method.
More codes for the above method are as follows:
Program 1: Here the date of the month should lie in between 1 to 31 because no date can have a month greater than 31. That is why it returns NaN i.e, Not a Number if the month in the Date object is greater than 31.
Program 2: If the month is not given, it returns zero (0).
Program 3: If nothing as a parameter is given, it returns the current month.
- Google Chrome 1 and above
- Edge 12 and above
- Firefox 1 and above
- Internet Explorer 4 and above
- Opera 3 and above
- Safari 1 and above