Date.getMonth()
JavaScript 1.0+, ECMAScript 1.0+, JScript 1.0+ Nav2+, NES2+, IE 3+, Opera3+ Syntax
date.getMonth()
Description
The getMonth() method returns the month portion of the Date object expressed as an integer from 0 (January) to 11 (December).
Example
The code in Listing 6.77 displays the current month using the getMonth() method.
Listing 6.77 Using the getMonth() Method to Return the Current Month
<html> <script language="JavaScript"> <!-- Hide //This function converts the month from a number to //a string and returns the string. function getMonthString(num) { var month; //Create a local variable to hold the string switch(num) { case 0: month="January"; break; case 1: month="February"; break; case 2: month="March"; break; ... |
Get Pure JavaScript now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.