A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.cdn.mozilla.net/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getYear below:

Date.prototype.getYear() - JavaScript | MDN

Date.prototype.getYear()

Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

The getYear() method of Date instances returns the year for this date according to local time. Because getYear() does not return full years ("year 2000 problem"), it is deprecated and has been replaced by the getFullYear() method.

Syntax Parameters

None.

Return value

An integer representing the year for the given date according to local time, minus 1900. Returns NaN if the date is invalid.

This method essentially returns the value of getFullYear() minus 1900. You should use getFullYear() instead, so that the year is specified in full.

Examples Years between 1900 and 1999

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

const xmas = new Date("1995-12-25");
const year = xmas.getYear(); // returns 95
Years above 1999

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

const xmas = new Date("2000-12-25");
const year = xmas.getYear(); // returns 100
Years below 1900

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

const xmas = new Date("1800-12-25");
const year = xmas.getYear(); // returns -100
Setting and getting a year between 1900 and 1999

The third statement assigns the value 95 to the variable year, representing the year 1995.

const xmas = new Date("2015-12-25");
xmas.setYear(95);
const year = xmas.getYear(); // returns 95
Specifications Browser compatibility See also

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4