Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between JavaScript's getYear() and getFullYear() functions?

Tags:

javascript

People also ask

What is difference between getYear and getFullYear in JavaScript?

getYear() returns year minus 1900 . This has been deprecated for a while now, it's best to use getFullYear() . Show activity on this post. Its a Y2K thing, basically getYear method returns the year minus 1900.

What is getFullYear () in JavaScript?

getFullYear() The getFullYear() method returns the year of the specified date according to local time.

How to get year from a date in JavaScript?

The getYear() method returns either a 2-digit or 4-digit year: For years between and including 1900 and 1999, the value returned by getYear() is the year minus 1900. For example, if the year is 1976, the value returned is 76.

How do you find the year from a full date?

Javascript date getFullYear() method returns the year of the specified date according to local time. The value returned by getFullYear() is an absolute number. For dates between the years 1000 and 9999, getFullYear() returns a four-digit number, for example, 2008.


It just makes no sense to me to get part of a year.

Back in the day, when memory was expensive and the Year 2000 was far in the future, it did make sense for people to represent 1975 as 75. In retrospect a short-sighted decision.

date.getFullYear() == date.getYear() + 1900

getYear() returns year minus 1900. This has been deprecated for a while now, it's best to use getFullYear().


Its a Y2K thing, basically getYear method returns the year minus 1900.

so, I encourage to move over to getFullYear & use that instead.