Alternative to GregorianCalendar


#1

In code listing 12.7, instead of using

I tried to re-use the same mDate object (instead of creating a new one as above) by updating the Year, month and day fields so as to preserve the time (and not having it reset to 00:00:00). But I faced a weird problem in that for the Date object passed back to CrimeFragment, date.toString() method turns the year 20yy into 39yy (so the year 2010 is turned into 3910, 2012 becomes 3912). But this problem mysteriously vanishes while using the new GregorianCalendar() object.

So I was wondering if others have also encountered this issue and if there was a reason for this odd behavior.


#2

Got the answer after browsing the java.util.Date API. Thanks to advice from StackOVerflow.


#3

Would you like to share your found answer?


#4

Basically, the year is stored by adding 1900 to it. So getYear(…) which is a deprecated function returns year - 1900. So date.toString() returns the representation (year + 1900). The advice in the documentation is to use the Calendar object to manipulate the dates and usage of the date manipulation API exposed by the Date class is deprecated.