setMonth()
Date
instance method setterS2C Home
« Globals « Date « setMonth()
Description
Sets the locale specific month of the year (0-11) for the specified date.
Syntax
Signature | Description |
---|---|
aDate.setMonth(monthInt[, dayInt]) | Sets the locale specific month of the year (0-11) for the specified date. |
Parameters
Parameter | Description |
---|---|
monthInt | An integer in the range 0-11. January=0, February=1 etc. |
dayInt | An integer in the range 1-31.
|
For specified values outside the ranges above the setMonth() method will try and set the date accordingly. |
Examples
The code below shows examples of the setMonth()
method of Date
.
// Create a Date instance for the current date and time.
var todaysDate = new Date();
alert(todaysDate);
// Set month.
todaysDate.setMonth(3);
alert(todaysDate + ' - Month set to 3');
// Set month and day.
todaysDate.setMonth(7,7);
alert(todaysDate + ' - Month and day set');
Related Tutorials
JavaScript Intermediate Tutorials - Lesson 2 - Dates and Times