setUTCFullYear()  Date  instance method setterS2C Home  « Globals « Date « setUTCFullYear()

Description

Sets the UTC year (CCYY) for the specified date.

Syntax

Signature Description
aDate.setUTCFullYear( yearInt[, monthInt[, dayInt]])Sets the UTC 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 getUTCMonth() method is used.
dayIntAn integer in the range 1-31.
  • If dayInt is not specified the value returned from the getUTCDate() method is used.
  • If dayInt is specified you must also specify monthInt.
For specified values outside the ranges above the setUTCFullYear() method will try and set the date accordingly.

Examples

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


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

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

// Set all parameters.
todaysDate.setUTCFullYear(2001,1,1);
alert(todaysDate + ' - UTC Year all parameters set');

Press the button below to action the above code:


Related Tutorials

JavaScript Intermediate Tutorials - Lesson 2 - Dates and Times

go to home page Homepage go to top of page Top