setFullYear()  Date  instance method JS Home  <<  JS Reference  <<  Date  <<  setFullYear()

Description

Sets the locale specific year (CCYY) for the specified date.

Syntax

Signature Description
aDate.setFullYear(yearInt[, monthInt[, dayInt]])Sets the locale specific year (CCYY) for the specified date.

Parameters

Parameter Description
yearIntAn integer specifying the year.
monthIntAn integer in the range 0-11. January=0, February=1 etc.
  • If monthInt is not specified the value returned from the getMonth() method is used.
dayIntAn integer in the range 1-31.
  • If dayInt is not specified the value returned from the getDate() method is used.
  • If dayInt is specified you must also specify monthInt.
For specified values outside the ranges above the setFullYear() method will try and set the date accordingly.

Examples

The code below displays shows examples of the setFullYear() method of Date.


// Create a Date instance for the current date and time.
var todaysDate = new Date();
alert(todaysDate);

// Set Year.
todaysDate.setFullYear(2005);
alert(todaysDate + ' - Year set to 2005');

// Set all parameters.
todaysDate.setFullYear(2001,1,1);
alert(todaysDate + ' - All parameters set');

Press the button below to action the above code:

Related Tutorials

JavaScript Intermediate Tutorials - Lesson 2 - Dates and Times