tags:

views:

161

answers:

3
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

+1  A: 

Those times in your Calendar don't look right. If those are supposed to be times in milliseconds, then 126..... represents a time of only 350 hours, which looks to be off by almost 40 years.

The reason seems to be that your initialization is not really setting your calendar to today's date. The initial date seems to be just a few hours past the epoch.

Please post some more code and we can fix it for you.

Carl Smotricz
+2  A: 

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.

Michael Borgwardt
+1  A: 
Calendar startCalTime = Calendar.getInstance(TimeZone.getTimeZone("America/Los_Angeles"));
Date d = new Date(creationTime);

What happens there? startCalTime and creationTime don't seem to be connected, I'd assume they should be?

Also for very slightly better performance/memory footprint, avoid new Integer/Long as much as possible and use Long/Integer.valueOf() instead.

Esko