This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
Hello Ranchers, I happen to encounter this when I was coding for date type conversions. I really don't have the hint why the day of the week is different as well as the long value. But the value will be the same when the MARKED LINE is commented out or setting the DEFAULT_YEAR's value to a value that is greater than 0. Someone has any idea?
GregorianCalendar does not have a year 0, nor any negative year for that matter. The correct representation of years prior to 1 AD is to set the ERA to BC. "Year 0" is 1 BC, while "year -1" would be 2 BC. Yes, this is pretty silly, but it's how the standard Gregorian calendar in the outside world was designed; GregorianCalendar merely reflects this. The GregorianCalendar class works correctly as long as you use legal values for the YEAR field; if you use 0 or negative values, it gives inconsistent results, as you've observed. The documentation for GregorianCalendar and Calendar is rather poor in this regard; they really should point out what the allowed values for year consist of. Further they really should throw IllegalArgumentExcecption when illegal arguments are used, rather than return inconsistent results. Of course, htis is just part of a long list of objections to the way Calendar is set up in Java. Oh well... [ October 18, 2003: Message edited by: Jim Yingst ]
"I'm not back." - Bill Harding, Twister
Joined: Oct 18, 2003
Thanks Jim, I do agree that the javadoc is quite poor; not describing the range of valid values for the fields. Anyway, let's just hope it will be fixed in the incoming versions... Mavedrive