METHOD:  Date::setUTCMonth

object.setUTCMonth(monthVal [, dayVal])

This method is used to set the month for the supplied date according to universal time. If you do not supply the dayVal argument, JavaScript will use the value returned using the getDate method. Also, if the supplied argument is outside the range expected, the setUTCMonth method will alter the other parameters of the date object accordingly (see example below).

The available parameters are as follows:

monthVal - an integer (0 for January thru 11 for December) representing the month.

dayVal - this value is an integer (1 thru 31) that represents the day of the month.

The following code uses the setUTCMonth method to change the value of the myDate object and also demonstrates how this method will adjust the other parameters if a value is supplied that exceeds the expected range. In this case the monthVal supplied is 13 which causes the year to be incremented by 1. This is calculated thus:

13 - 12 (maximum expected value for seconds) = 1 (this increments the year by one).

The result of this calculation (1 = February) is then used for the monthVal parameter.

myDate = new Date()
document.write(myDate +"<br>")

Fri Jul 9 13:47:32 UTC+0100 1999
Wed Feb 9 13:16:40 UTC+0100 2000

Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information