setUTCFullYear (JavaScript)

Sets the year in UTC. Optionally sets the month and day.

Defined in

Date (Standard - JavaScript)

Syntax

setUTCFullYear(year:int) : long

setUTCFullYear(year:int, month:int) : long

setUTCFullYear(year:int, month:int, day:int) : long

Parameters Description
year The full year in UTC.
month The month in UTC where 0 is January.
date The day of the month in UTC where 1 is the first day of the month.
Return value Description
long The new time in numeric format.

Examples

(1) This computed label adds one year to the current date. One day is first subtracted if the date is February 29 (leap year) so it appears as February 28 instead of March 1 in the next year.
// Next year same time
var date = new Date();
if(date.getUTCMonth() == 1) // if Feb
	if(date.getUTCDate() > 28) // if Feb 29
		date.setUTCDate(date.UTCgetDate() - 1);
date.setUTCFullYear(date.getUTCFullYear() + 1);
date.toUTCString()
(2) This computed label changes the year of the current date and displays it as a new Date object.
var date = new Date();
new Date(date.setUTCFullYear(2001)).toString()
(3) This computed label changes the year and month of the current date and displays it as a new Date object.
var date = new Date();
new Date(date.setUTCFullYear(2001, 0)).toString()
(4) This computed label changes the year, month, and day of the current date and displays it as a new Date object.
var date = new Date();
new Date(date.setUTCFullYear(2001, 0, 1)).toString()