Date.setFullYear() (Method)

Sets the full year value of a date/time object.


ECMAScript edition - 2
JavaScript - 1.3
JScript - 3.0
Internet Explorer - 4.0
Netscape - 4.0
Property/method value type:Time value
JavaScript syntax:-myDate.setFullYear(aYearValue)
-myDate.setFullYear(aYearValue, aMonthValue)
-myDate.setFullYear(aYearValue, aMonthValue, aDateValue)
Argument list:aDateValueAn optional date within the month value
aMonthValueAn optional 0 to 11 month value
aYearValueA full year value

The result returned by this method will be the new time value of the containing object, having been adjusted by the values passed in as arguments.

The computations are carried out in local time coordinates.

ECMA mandates that the month and date should be optional arguments. If the date value is omitted, the value is provided internally as if the getDate() method had been invoked to provide it. Likewise the month value will be replaced by internally calling the getMonth() method.

Example code:

   myArray = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
   myDate = new Date();
   myDate.setFullYear(myDate.getFullYear() - 1);
   document.write("A year ago on today's date, it was a " + myArray[myDate.getDay()]);

See also:Date.getFullYear(), Date.getYear(), Date.prototype, Date.setUTCFullYear(), Date.setYear()


ECMA 262 edition 2 - section -

ECMA 262 edition 3 - section -