I am using Calendar Class in my android app to calulate day of year of a date and then do some comparison with current day of year. Here is the code I use :
Date now=new Date(); Calendar ca1 = Calendar.getInstance(); ca1.set(now.getYear(), now.getMonth(), now.getDate()); int nowC=ca1.get(Calendar.DAY_OF_YEAR); //Date arg0=say,get from user Calendar ca2 = Calendar.getInstance(); ca2.set(arg0.GetBirthDay().getYear(),arg0.GetBirthDay().getMonth(),arg0.GetBirthDay().getDate()); int d1C=ca2.get(Calendar.DAY_OF_YEAR);
I debug my application and I see the following value for current day : Fri Mar 02 14:18:33 Asia/Tehran 2012
and for arg0: Fri Mar 02 00:00:00 Asia/Tehran 1979
And 'nowC' got 62, and 'd1C' got 61.
I expect them to be equal cause both of them has same month and day, also If I use DateTime class of joda package, as below, I get the same results:
int ndy=dtnow.getDayOfYear(); int d1dy=dt1.getDayOfYear();
Why it is happening ?