Issue with GregorianCalendar class
Hi I'm having issues with the GregorianCalender class. I am trying to enable daylight savings time but it doesn't seem to be working properly for. As a test I have taken the difference of time (in milliseconds) between a date where daylight savings causes a shift in time (April 4, 2004 for example). The two sample dates I have chosen are April 5, 2004 and April 4, 2004, ideally the time difference should be 23 hrs (since one hour is lost due to daylight savings) but I am getting 24hrs. I have a sample program in C++ which gives me the correct answer so I know the result am I getting here is wrong. Anybody have any suggestions?
String[] ids = TimeZone.getAvailableIDs(-8 * 60 * 60 * 1000);
if (ids.length == 0)
System.exit(0);
// create a Pacific Standard Time time zone
SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, ids[0]);
// set up rules for daylight savings time
pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 60 * 60 * 1000, true);
pdt.setEndRule(Calendar.OCTOBER, 31, Calendar.SUNDAY, 60 * 60 * 1000, false);
pdt.setDSTSavings( 60*60*1000 );
GregorianCalendar cal = new GregorianCalendar(2004, 4, 4);
GregorianCalendar cal1 = new GregorianCalendar(2007, 4, 5);
cal1.setTimeZone ( pdt );
cal.setTimeZone( pdt );
//This values is incorrect
long diff = cal1.getTimeInMillis() - cal.getTimeInMillis();
//I have also tried the following
String[] ids = TimeZone.getAvailableIDs(-8 * 60 * 60 * 1000);
if (ids.length == 0)
System.exit(0);
// create a Pacific Standard Time time zone
SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, ids[0]);
// set up rules for daylight savings time
pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 60 * 60 * 1000, true);
pdt.setEndRule(Calendar.OCTOBER, 31, Calendar.SUNDAY, 60 * 60 * 1000, false);
pdt.setDSTSavings( 60*60*1000 );
GregorianCalendar cal = new GregorianCalendar(pdt);
GregorianCalendar cal1 = new GregorianCalendar(pdt);
cal1.set(2004, 4, 5 );
cal.set( 2004, 4, 4 );
//This values is incorrect
long diff = cal1.getTimeInMillis() - cal.getTimeInMillis();
Thanks

