setFullYear (JavaScript)

Sets the year in local time. Optionally sets the month and day.

Defined in

Date (Standard - JavaScript)

Syntax

setFullYear(year:int) : long

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

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

Parameters Description
year The full year in local time.
month The month in local time where 0 is January.
day The day of the month in local time 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.getMonth() == 1) // if Feb
	if(date.getDate() > 28) // if Feb 29
		date.setDate(date.getDate() - 1);
date.setFullYear(date.getFullYear() + 1);
date.toString()
(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.setFullYear(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.setFullYear(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.setFullYear(2001, 0, 1)).toString()