Why Does JavaScript Getyear() Return 108

Why does Javascript getYear() return a three digit number?

It's a Y2K thing, only the years since 1900 are counted.

There are potential compatibility issues now that getYear() has been deprecated in favour of getFullYear() - from quirksmode:

To make the matter even more complex, date.getYear() is deprecated nowadays and you should use date.getFullYear(), which, in turn, is not supported by the older browsers. If it works, however, it should always give the full year, ie. 2000 instead of 100.

Your browser gives the following years with these two methods:

* The year according to getYear(): 108
* The year according to getFullYear(): 2008

There are also implementation differences between Internet Explorer and Firefox, as IE's implementation of getYear() was changed to behave like getFullYear() - from IBM:

Per the ECMAScript specification, getYear returns the year minus 1900, originally meant to return "98" for 1998. getYear was deprecated in ECMAScript Version 3 and replaced with getFullYear().

Internet Explorer changed getYear() to work like getFullYear() and make it Y2k-compliant, while Mozilla kept the standard behavior.

javascript date getYear() returns different result between IE and Firefox, how to approach this?

Use getFullYear() instead of getYear().

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

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

Issue in Parsing date in Javascript

getYear is documented to return the year minus 1900, so you are actually getting the expected value. It's also deprecated. Use getFullYear to receive 2011.

javascript date and year

It is correct. .getYear() returns "actual year − 1900". 2010 − 1900 = 110.

Use .getFullYear() instead. .getYear() has been deprecated for a long time.

How to determine one year from now in Javascript

You should use getFullYear() instead of getYear(). getYear() returns the actual year minus 1900 (and so is fairly useless).

Thus a date marking exactly one year from the present moment would be:

var oneYearFromNow = new Date();
oneYearFromNow.setFullYear(oneYearFromNow.getFullYear() + 1);

Note that the date will be adjusted if you do that on February 29.

Similarly, you can get a date that's a month from now via getMonth() and setMonth(). You don't have to worry about "rolling over" from the current year into the next year if you do it in December; the date will be adjusted automatically. Same goes for day-of-month via getDate() and setDate().

jquery ui datepicker return weird year

You need to get they year using getFullYear(). I guess you must be using getYear().



Related Topics



Leave a reply



Submit