Usage of the setMonth () method in JavaScript
The javascript Date. setMonth () method sets the specified Date of each month according to the local time.
Syntax
1 |
Date. setMonth (monthValue [, dayValue]) |
Note: The appearance and data in the brackets are optional.
The following is the detailed information about the parameters:
- MonthValue: an integer from 0 to 11 (representing a month, from January 1, January to January 1, December ).
- DayValue: an integer from 1 to 31, representing a day in a month.
- MsValue: a number between 0 and 999, indicating milliseconds. If the msValue parameter is specified, minutesValue and secondsValue must also be specified.
If the dayValue parameter is not specified, the value returned from the getDate method is used. If the specified parameter is out of the expected range, setMonth tries to update the latest information of the Date object accordingly. For example, if the value of monthValue is 15, year will increase the increment of 1 (year + 1), and 3 will be used for the month value.
Return Value:
Example:
1 2 3 4 5 6 7 8 9 10 11 12 |
<Html> <Head> <Title> JavaScript setMonth Method </title> </Head> <Body> <Script type = "text/javascript"> Var dt = new Date ("Aug 28,200 8 23:30:00 "); Dt. setMonth (2 ); Document. write (dt ); </Script> </Body> </Html> |
This produces the following results:
1 |
Fri Mar 28 23:30:00 UTC + 0530 2008 |