JavaScript Date getYear() Method
JavaScript date.getYear() is used to get the year on a specified date according to universal time. The year we get from the method getYear() is the current year minus 1900.
Syntax:
date.getYear();Parameters:
- This function does not accept any parameters.
Return Value:
- This method returns a value that is subtracted from 1900 to the current year.
Example 1: This example returns the year of the specified date according to universal time.
// "date" is object of Date() class
let date = new Date();
// Use "getYear()" method and stores
// the returned value to "n"
let n = date.getYear();
// Display the result
console.log("The value returned by getYear() method: " + n)
Output:
The value returned by getYear() method: 119Example 2: This example only sends the year to the constructor.
// Year 2000 is assign to the
// constructor of Date() class
let date = new Date('2000')
// Use "getYear()" method and stores
// the returned value to "n"
let n = date.getYear();
// Display the returned value
// The value is the subtraction of
// 2000 and 1900
console.log("The value returned by getYear() method: " + n)
Output:
The value returned by getYear() method: 100Example 3: Here, we pass a full date to the constructor, the format of the date is month-day-year-time, such as October 15, 2010, 02:05:32.
// Full date is assign to the constructor of Date() class
let date = new Date('October 15, 2010, 02:05:32')
// Use "getYear()" method and stores the
// returned value in "n"
let n = date.getYear();
// Display the returned value
// The value is the subtraction of 2010 and 1900
console.log("The value returned by getYear() method: " + n)
Output
The value returned by getYear() method: 110
Supported Browsers:
- Google Chrome
- Mozilla Firefox
- Opera
- Safari
JavaScript Date getYear() Method- FAQs
What does the Date.prototype.getYear() method do in JavaScript?
The Date.prototype.getYear() method returns the year of the specified date according to local time, minus 1900.
Why is getYear() considered deprecated?
The getYear() method is deprecated because it can lead to confusion and errors due to its non-standard behavior. It is recommended to use getFullYear() instead.
What should I use instead of getYear()?
You should use the getFullYear() method instead. getFullYear() returns the full year value as a four-digit number, which avoids the confusion caused by getYear().
How does getYear() handle dates in the 21st century?
For dates in the 21st century, getYear() returns values greater than 100. For example, for the year 2023, it returns 123.
What is the most common use of the Date.prototype.getYear() method?
- Maintaining compatibility with older codebases.
- Working with dates in legacy systems that use
getYear().- Migrating legacy code to modern standards by replacing
getYear()withgetFullYear().
We have a complete list of Javascript Date Objects, to check those please go through this Javascript Date Object Complete reference article.


