Home arrow static arrow Java Programming [Archive] - problem setting a specific date
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - problem setting a specific date
This topic has 1 reply on 1 page.

Posts:2
Registered: 8/4/04
problem setting a specific date  
Aug 4, 2004 11:34 PM



 
It seems I cannot set the datetime to 28/03/2005 02:00:00 (the problem is the hour).
I have the following pieces code:

1.
Date d0 = new Date("03/28/2004 02:00:00");
System.out.println(d0);
prints out Sun Mar 28 03:00:00 CEST 2004: the hour is 3 instead of 2

2.
Calendar startCal = GregorianCalendar.getInstance(Locale.ITALY);
startCal.set(Calendar.DAY_OF_MONTH, 28);
startCal.set(Calendar.MONTH, Calendar.MARCH);
startCal.set(Calendar.YEAR, 2004);
startCal.set(Calendar.HOUR_OF_DAY, 0);
startCal.set(Calendar.MINUTE, 0);
startCal.set(Calendar.SECOND, 0);
startCal.set(Calendar.MILLISECOND, 0);
Date start = startCal.getTime();

Calendar endCal = GregorianCalendar.getInstance();
endCal.set(Calendar.DAY_OF_MONTH, 28);
endCal.set(Calendar.MONTH, Calendar.MARCH);
endCal.set(Calendar.YEAR, 2004);
endCal.set(Calendar.HOUR_OF_DAY, 5);
endCal.set(Calendar.MINUTE, 0);
endCal.set(Calendar.SECOND, 0);
endCal.set(Calendar.MILLISECOND, 0);
Date end = endCal.getTime();

while(!startCal.getTime().after(end)){
startCal.add(Calendar.HOUR_OF_DAY, 1);
System.out.println(startCal.getTime());
}
It prints out
Sun Mar 28 01:00:00 CET 2004
Sun Mar 28 03:00:00 CEST 2004
Sun Mar 28 04:00:00 CEST 2004
Sun Mar 28 05:00:00 CEST 2004
Sun Mar 28 06:00:00 CEST 2004
and it skips Sun Mar 28 03:00:00 CEST 2004

3.
Calendar cal = GregorianCalendar.getInstance(Locale.ITALY);
cal.set(Calendar.DAY_OF_MONTH, 28);
cal.set(Calendar.MONTH, Calendar.MARCH);
cal.set(Calendar.YEAR, 2004);
cal.set(Calendar.HOUR_OF_DAY, 2);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
Date d = cal.getTime();
System.out.println(d);
it prints out Sun Mar 28 03:00:00 CEST 2004 !!!!

It seems I am unable to set hour to 2 am for the 28th March 2004. The same for 27th 2005.
Where I am wrong ? Is it a bug ?

thanks for your help
 

Posts:10,967
Registered: 4/7/01
Re: problem setting a specific date  
Aug 5, 2004 1:00 PM (reply 1 of 1)



 
Daylight Savings Time started (in CEST timezone) at 02:00 March 28. (See http://www.timeanddate.com/time/dstevents.html )

Your apparently have a timezone set in the computer (CEST?) that is observing this change. Technically there was no elapsed time between 01:59.59 and 03:00.00 that date.
 
This topic has 1 reply on 1 page.