| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getYear | [Back] [Original] |
Get to know MDN better
Avoid using this feature in new projects.
The getYear() and setYear() methods use a truncated number instead of the actual year number, known as a year 2000 problem.
This feature may be a candidate for removal from web standards or browsers.
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.
getYear()
None.
An integer representing the year for the given date according to local time, minus 1900. Returns NaN if the date is invalid.
getYear() returns 126.getYear() is between 0 and 99. For example, if the year is 1976, getYear() returns 76.getYear() is less than 0. For example, if the year is 1800, getYear() returns -100.This method essentially returns the value of getFullYear() minus 1900. You should use getFullYear() instead, so that the year is specified in full.
The second statement assigns the value 95 to the variable year.
const xmas = new Date("1995-12-25");
const year = xmas.getYear(); // returns 95
The second statement assigns the value 100 to the variable year.
const xmas = new Date("2000-12-25");
const year = xmas.getYear(); // returns 100
The second statement assigns the value -100 to the variable year.
const xmas = new Date("1800-12-25");
const year = xmas.getYear(); // returns -100
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
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-date.prototype.getyear |
Date.prototype.getYear in core-jsDate.prototype.getYearDate.prototype.getFullYear()Date.prototype.getUTCFullYear()Date.prototype.setYear()This page was last modified on Jul 10, 2025 by MDN contributors.
DategetDate()getDay()getFullYear()getHours()getMilliseconds()getMinutes()getMonth()getSeconds()getTime()getTimezoneOffset()getUTCDate()getUTCDay()getUTCFullYear()getUTCHours()getUTCMilliseconds()getUTCMinutes()getUTCMonth()getUTCSeconds()getYear()setDate()setFullYear()setHours()setMilliseconds()setMinutes()setMonth()setSeconds()setTime()setUTCDate()setUTCFullYear()setUTCHours()setUTCMilliseconds()setUTCMinutes()setUTCMonth()setUTCSeconds()setYear()toDateString()toISOString()toJSON()toLocaleDateString()toLocaleString()toLocaleTimeString()toString()toTemporalInstant()toTimeString()toUTCString()valueOf()[Symbol.toPrimitive]()Object/FunctionYour blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |