Date.getYear

Returns the year in the specified date according to local time.
Method of Date (deprecated)

Syntax

getYear()

Parameters

None

Description

getYear is no longer used and has been replaced by the Date.getFullYear method.
The getYear method returns the year minus 1900; thus:
For years above 2000, the value returned by getYear is 100 or greater. For example, if the year is 2026, getYear returns 126.
For years between and including 1900 and 1999, the value returned by getYear is between 0 and 99. For example, if the year is 1976, getYear returns 76.
For years less than 1900 or greater than 1999, the value returned by getYear is less than 0. For example, if the year is 1800, getYear returns -100.
To take into account years before and after 2000, you should use Date.getFullYear instead of getYear so that the year is specified in full.

Examples

Example 1. The second statement assigns the value 95 to the variable year.

Example 2. The second statement assigns the value 100 to the variable year.

Example 3. The second statement assigns the value -100 to the variable year.

Example 4. The second statement assigns the value 95 to the variable year, representing the year 1995.

See also

Date.getFullYear, Date.getUTCFullYear, Date.setYear

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.