|
Hi Alex,
I don't have time at the moment to try out your code, but I suspect,
given the dates involved, that it has to do with the Daylight Savings Time
change. In the US, it starts at 2 a.m. on April 4, 2004. Try setting the
time to something after 1 in the morning.
Joe Sam
Joe Sam Shirah - http://www.conceptgo.com
conceptGO - Consulting/Development/Outsourcing
Java Filter Forum: http://www.ibm.com/developerworks/java/
Just the JDBC FAQs: http://www.jguru.com/faq/JDBC
Going International? http://www.jguru.com/faq/I18N
Que Java400? http://www.jguru.com/faq/Java400
----- Original Message -----
From: "Alex Pinsky" <apinsky@xxxxxxxxxxxxxxx>
To: "Java AS/400 forum (E-mail)" <java400-l@xxxxxxxxxxxx>
Sent: Wednesday, March 24, 2004 12:07 PM
Subject: problem with 04/04/2004 GregorianCalendar date
> Hi all,
> I came across very strange problem when roll method in GregorianCalendar.
> When rolling down from given date - calendar skips 04/04/2004 and rolls to
the 04/03/2004
> When I roll up - dates are correct.
> Here is the code that I use, please test...
>
> try {
> SimpleDateFormat mmddyyyy = new SimpleDateFormat("MM/dd/yyyy");
> SimpleDateFormat wd = new SimpleDateFormat("E");
>
> String[] weekdates = new String[7];
> String[] weekdays = new String[7];
>
> GregorianCalendar cal = new GregorianCalendar();
> java.util.Date date = mmddyyyy.parse("04/09/2004");
>
> cal.setTime(date);
>
> for (int i=0; i<weekdates.length; i++) {
> cal.roll(Calendar.DAY_OF_YEAR, false);
> date = cal.getTime();
> weekdays[i] = wd.format(date);
> weekdates[i] = mmddyyyy.format(date);
> }
> // print result
> System.out.println("Result of rolling down");
> for (int i=0; i<weekdates.length; i++) {
> System.out.println(weekdays[i]+"; "+weekdates[i]);
> }
>
> // start rollup
> date = mmddyyyy.parse("04/02/2004");
>
> cal.setTime(date);
>
> for (int i=0; i<weekdates.length; i++) {
> cal.roll(Calendar.DAY_OF_YEAR, true);
> date = cal.getTime();
> weekdays[i] = wd.format(date);
> weekdates[i] = mmddyyyy.format(date);
> }
> // print result
> System.out.println("Result of rolling up");
> for (int i=0; i<weekdates.length; i++) {
> System.out.println(weekdays[i]+"; "+weekdates[i]);
> }
>
> } catch (Exception e) {
> e.printStackTrace();
> }
>
> // my print output: please not that there is no Sunday when roll down
used!!!!
> Result of rolling down
> Thu; 04/08/2004
> Wed; 04/07/2004
> Tue; 04/06/2004
> Mon; 04/05/2004
> Sat; 04/03/2004
> Fri; 04/02/2004
> Thu; 04/01/2004
>
> Result of rolling up
> Sat; 04/03/2004
> Sun; 04/04/2004
> Mon; 04/05/2004
> Tue; 04/06/2004
> Wed; 04/07/2004
> Thu; 04/08/2004
> Fri; 04/09/2004
>
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.