JavaScript » Date » setUTCFullYear

Syntax:
object.setUTCFullYear(yearVal [, monthVal, dayVal])
yearVal
this value is an integer representing the year, e.g. 1999
monthVal
an integer representing the month (0 for January thru 11 for December)
dayVal
this value is an integer that represents the day of the month (1 thru 31).

This method is used to set the full year for the supplied date according to universal time.

This method is used to set the full year for the supplied date according to universal time. If you do not supply the monthVal and dayVal arguments, JavaScript will use the values returned using the getMonth and getDay methods. Also, if the supplied argument is outside the range expected, the setUTCFullYear method will alter the other parameters accordingly (see example below).

Examples

Code:
myDate = new Date()
document.write(myDate +"<br>")
myDate.setUTCFullYear(1999, 08, 35)
document.write(myDate)
Output:
Fri Jul 9 12:32:32 UTC+0100 1999
Sat Sep 4 12:32:32 UTC+0100 1999
Explanation:

This example uses the setUTCFullYear 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 dayVal supplied is 35 which causes the monthVal value to be incremented by 2.

This is calculated thus:
35 - 31(maximum expected value for month) = 4 (this increments monthVal by one).

The result is that setUTCFullYear method uses 4 for for the dayVal and increments the monthVal by one, from 8 to 9.