Java.util.Calendar not reporting the correct timeInMillis


findCalendarStart: time into Calendar: 1260575897

findCalendarStart: set hour : 13

findCalendarStart: after hour : 1249775897

findCalendarStart: after hour string: Thu Jan 15 11:09:35 UTC 1970

findCalendarStart: set minutes  : 13

findCalendarStart: after minutes: 1250015897

findCalendarStart: what calendar returns: 1250015897

I place a Date (initialized by passing long from a millisecond from today) in a Calendar. Calendar is correctly initialized. In the first calculation, I change the hour of day to 13. At this point, startCalTime.set(Calendar.HOUR_OF_DAY, ((new Integer(*2)-1 );

I am passing the right hour of day values and minutes because Im seeing them in the logger. What could possibly be causing calendar to come up with such strange dates after I only change the hour of day from todays Date object?

More code:

Calendar startCalTime = Calendar.getInstance(TimeZone.getTimeZone("America/Los_Angeles"));
Date d = new Date(creationTime);


_logger.warning("set hour 1 : " + new Integer((new Integer(;                         startCalTime.set(Calendar.HOUR_OF_DAY, new Integer( );
_logger.warning("after hour 1:  " + new Long(startCalTime.getTime().getTime()));
_logger.warning("after hour 1 string:  " + startCalTime.getTime().toString());  
_logger.warning("set minutes 1 : " + new Integer(;
startCalTime.set(Calendar.MINUTE, new Integer(;
_logger.warning("after minutes 1:  " + new Long(startCalTime.getTime().getTime()));}



Best Solution

Let's see how you initialize your date. I suspect that instead of milliseconds, you are passing it seconds since epoch start - this (seconds, not milliseconds) is how regular Unix timestamps are defined. Java uses milliseconds for better granularity.