JavaScript tutorial:
getMonth Method

 

Applies to: Date Object

The getMonth method is ure to get the month value in the Date object using local time.

Syntax

objDate.getMonth()Return

Return

Returns the month value in the Date object using local time.

Example

To get the month value using Universal Coordinated Time (UTC), use the getUTCMonth method.

The getMonth method returns an integer between 0 and 11 indicating the month value in the Date object. The integer returned is not the traditional number used to indicate the month. It is one less. If "Jan 5, 1996 08:47:00" is stored in a Date object, getMonth returns 0.

The following example illustrates the use of the getMonth method:

function DateT()
{
    var d, s = "Today's date is: ";
    d = new Date();
    s += (d.getMonth() + 1) + "/";
    s += d.getDate() + "/";
    s += d.getFullYear();
    return(s);
}

document.write(DateT());

To run the code above, paste it into JavaScript Editor, and click the Execute button

See also : Date Object Methods, getUTCMonth Method, setMonth Method, setUTCMonth Method