File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes JDK1.3 calendar problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "JDK1.3 calendar problem" Watch "JDK1.3 calendar problem" New topic

JDK1.3 calendar problem

Kevin P Smith
Ranch Hand

Joined: Feb 18, 2005
Posts: 362
Hi all

I was just wondering if anyone knew of a problem with Java version 1.3 calendar?

The reason i ask is that I have a small class which calculates the number of
working days (excluding bank holidays, as I can't work a way round them)
between to dates.

However I have noticed that for some dats it's calculating the days right and
others it seems a day out.


08/06/2005 to 10/06/2005 = 1 day, WRONG,
07/06/2005 to 10/06/2005 = 2 days, WRONG,
06/06/2005 to 08/06/2005 = 2 days, RIGHT,
07/06/2005 to 08/06/2005 = 1 day, RIGHT,
27/05/2005 to 01/06/2005 = 4 days, WRONG!

Sample code:
for (long l=StartDate.getTime();l<EndDate.getTime();l=l+86400000) {
day = newCal.get(Calendar.DAY_OF_WEEK);
if ((day>1) && (day<7)) {
retStr = new Integer(numdays).toString();

Any help, greatly recieved... Cheers

Frank Ertl
Ranch Hand

Joined: Apr 25, 2005
Posts: 59

looking at your code-example I see that you change your Calendar-object newCal inside the for-loop. I think that's the reason, because changing the DATE-field has effect on the DAY_OF_WEEK.
Try to change this and I think it'll work correct.
I agree. Here's the link:
subject: JDK1.3 calendar problem
It's not a secret anymore!