i'm using the getTimeInMillis() function from the Calendar class to calculate the number of milliseconds from the epoch to a particular day. however, it seems as if the function is returning wrong values by assuming that every month has 31 days.
a sample code I tested is as follows:
long mili; Calendar now = new GregorianCalendar(); now.set(2011, 02, 28); mili = now.getTimeInMillis(); System.out.println(mili); now.set (2011, 03, 01); mili = now.getTimeInMillis(); System.out.println(mili); now.set(1970, 1, 1); mili = now.getTimeInMillis(); System.out.println(mili);
the output i got was 1301280211567 for 2011/02/28 and 1301625811567 for 2011/03/01, there is a four day difference in the milliseconds, when there should only have been one.
also, the output i got for 1970/01/01 is 2688211567. shouldn't this have been zero if getTimeInMilils() calculates starting from the epoch which is exactly 1970/01/01?
is there something i'm not doing correctly or is this really a bug in the function? if it is, is there any other way i can calculate the number of milliseconds to a certain day?
thanks!