setFullYear()
Date
instance method setterS2C Home
« Globals « 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 |
---|---|
yearInt | An integer specifying the year. |
monthInt | An integer in the range 0-11. January=0, February=1 etc.
|
dayInt | An integer in the range 1-31.
|
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');
Related Tutorials
JavaScript Intermediate Tutorials - Lesson 2 - Dates and Times