Java.util.Calendar not reporting the correct timeInMillis

calendarjava

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(m.group(1)).intValue())*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);
startCalTime.setTime(d);       
 startCalTime.getTimeInMillis();

..regex..

if(m.find()){
//SET HOUR OF DAY
_logger.warning("set hour 1 : " + new Integer((new Integer(m.group(1)).intValue())-1));                         startCalTime.set(Calendar.HOUR_OF_DAY, new Integer(m.group(1)).intValue()-1 );
_logger.warning("after hour 1:  " + new Long(startCalTime.getTime().getTime()));
_logger.warning("after hour 1 string:  " + startCalTime.getTime().toString());  
//SET MINUTE
_logger.warning("set minutes 1 : " + new Integer(m.group(2).toString()));
startCalTime.set(Calendar.MINUTE, new Integer(m.group(2)).intValue());
_logger.warning("after minutes 1:  " + new Long(startCalTime.getTime().getTime()));}

Thanks,

culov

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.