This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
I am completely lost with this thing! I have to compare 2 dates and figure out if they're within x amount of hours. I'm testing with 2. I have to set the timezone to the input timezone. I create 2 gregorian dates to whatever the input timezone is. Then I add the hours to the comparison date. My problem is that it's printing the timezone as cst (what I'm testing with) but the time is calculating in est. Also, it looks like the requested date also gets added. They're 2 separate dates so I don't see how one value could be affecting the other. Can anyone see what I'm doing wrong with this? This is the output: Initial Set. current: Thu Feb 05 20:55:15 EST 2004 req: Thu Feb 05 20:55:15 EST 2004 Before set current: Thu Feb 05 22:55:15 EST 2004 Requested after reset Thu Feb 05 19:00:15 EST 2004 Now the biggee, is it within 2 hours? 1 Interactive Session Ended This is the code: //Converts GMT to CST String ids = TimeZone.getAvailableIDs(-6 * 60 * 60 * 1000); SimpleTimeZone cst = new SimpleTimeZone(-6 * 60 * 60 * 1000, ids); //Calculate the day light savings time changes cst.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); cst.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
//requested is military format, use HOUR_OF_DAY //.add forces recalculation varCurrentCal.add(Calendar.HOUR_OF_DAY, 2); //System.out.println("Added 2 hours to current: " + varCurrentCal.getTime());
//requested date/time entered int year = 2004; int month = 02; int day = 05; int hour = 18; int minute = 00;
System.out.println("Before set current: " + varCurrentCal.getTime()); varCurrentCal.getTime();
varReqCal.set(year,(month -1),day,hour,minute); varReqCal.getTime(); System.out.println("Requested after reset " + varReqCal.getTime()); int delThis = varCurrentCal.getTime().compareTo(varReqCal.getTime()); System.out.println("Now the biggee, is it within 2 hours? " + delThis);