JavaScript tutorial:
getFullYear method

 

Applies to: Date Object

The getFullYear method is use to get the year value in the Date object using local time.

Syntax

objDate.getFullYear()

Return

Returns the year value in the Date object using local time.

Example

To get the year using Universal Coordinated Time (UTC), use the getUTCFullYear method.

The getFullYear method returns the year as an absolute number. For example, the year 1976 is returned as 1976. This avoids problems with dates occuring at the end of the 20th century.

s = "Today's UTC date is: ";
d = new Date();
s += (d.getMonth() + 1) + "/";
s += d.getDate() + "/";
s += d.getFullYear();

document.write(s);

To run the code above, paste it into JavaScript Editor, and click the Execute button

See also: Date Object Methods, getUTCFullYear Method, setFullYear Method, setUTCFullYear Method