Closed Bug 155995 Opened 22 years ago Closed 20 years ago

JavaScript Date.getYear() function returns the WRONG year.

Categories

(Core :: JavaScript Engine, defect)

x86
Windows 2000
defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 22964

People

(Reporter: tomdkat, Assigned: rogerl)

References

Details

From Bugzilla Helper: User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0rc2) Gecko/20020513 Netscape/7.0b1 BuildID: 20020530 When I use the Date.getYear() function, I expect to receive "2002" but I get "201" instead. This happens in Netscape 7.0PR1 on Linux as well. Reproducible: Always Steps to Reproduce: 1.Open the HTML testcase in the "Additional info" section 2.The year 2002 should appear and NOT "201". 3. Actual Results: "201" is returned INSTEAD of "2002". Expected Results: "2002" should be returned. Here is an HTML test case which illustrates the problem: <?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> </head> <body> <script language="JavaScript1.2" type="text/JavaScript"> <!--date=new Date(); var date = new Date(); var year = date.getYear(); document.write("This is the year we get from the javascript->" + year+" which should read 2002.") //--> </script> </body> </html>
I don't think this is a bug :-) getYear() is based on the number of years since 1900 :-) For full and real date, why not using getFullYear (since JS 1.2 if I am right ?) Marking this bug as invalid ?
Worksforme in Windows NT, build 2202061104 (1.1a), I'm getting 102. Mozilla returns a date relative to 1900. For an explanation, see http://tech.irt.org/articles/js199/ and http://www.webreference.com/js/tips/000707.html In JavaScript 1.2 (which you're using here), you should use getFullYear(), to make sure that your get the full year. Several browsers implemented this in a different way (relative to 1900, relative to 1970, full year, ...). Unless you're doing browser-sniffing to correct this, you should use getFullYear().
And it's on of those nasty Y2k bugs too (remember when the sky was supposed to fall on our heads ?) - everyone had to be careful with the result of those functions, not just for the implementation in the browser, but also for the Y2K problem. You're sure thast you saw '201' ? Not '102' ?
*** This bug has been marked as a duplicate of 100123 ***
Status: UNCONFIRMED → RESOLVED
Closed: 22 years ago
Resolution: --- → DUPLICATE
Thanks for the info guys! I opened his bug report in the middle of the night, so it IS likely that I transposed the digits and meant "102" when I typed "201". Peace.....
Verified Duplicate -
Status: RESOLVED → VERIFIED
Status: VERIFIED → UNCONFIRMED
Resolution: DUPLICATE → ---
*** This bug has been marked as a duplicate of 22964 ***
Status: UNCONFIRMED → RESOLVED
Closed: 22 years ago20 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.