Man, I appreciate the offer BigLee. Jim Scarborough has gotten me thru these
last few difficult days playing with date calculations. I think I am on
track for now. And you're right, it is more difficult than it should be to
get going on some of the basic business needs. At least when first starting
off with Java. I am a newbie to Java and clearly am making plenty of newbie
mistakes .. oh well, keeps things interesting .. Thanks again..


-----Original Message-----
From: BigLee Haslup [mailto:[EMAIL PROTECTED]
Sent: Monday, June 16, 2003 1:11 PM
To: [EMAIL PROTECTED]
Subject: Re: [Juglist] Help


Hello Chuck,

     It's amusing how difficult this is, isn't it?  If you do a Google 
search you will find a number of examples of solutions that don't work -- 
or rather, solutions that give answers that are technically correct but 
aren't what you wanted.  The problem you are running into is daylight 
savings time and/or leap seconds.  The GregorianCalendar will tell you the 
number of milliseconds between two dates but is rather vague about how many 
days that is.  You see, some days are 23 hours long and others are 25 
(daylight savings) and some days are 24 hours and one second long (leap 
seconds).

    The Java Date/Time classes are exactly what you need to launch a probe 
to Uranus but are maddening to try to use for business calculations.  One 
always feels like Captain Kirk trying to get Mr. Spock to answer a simple 
question.

    If you are just interested in subtracting even-day dates you could try 
adding enough milliseconds to make, say, four hours before you divide by 
the number of milliseconds in a day (then truncate to an 
integer).  Alternatively, you could look for a different calendar class 
that is more amenable to business calculations.  My Google search found 
several but I haven't taken the time to find one I liked.  I also have some 
classes that I wrote several years ago that implement a simplified time 
model where all days are 24 hours long, all hours have exactly 60 minutes, 
etc..  If you are interested I will see if I can find them.  They are a 
couple of years old and may have some deprecated (old-style) calls to 
system classes but I would love to put them back in service.  They were 
pretty handy.

Lee Haslup


At 10:10 AM 6/16/2003 -0400, you wrote:
>I am new to Java and could use some advice, help, examples .. anything I 
>can get ..
>
>I am trying to calculate the number of days between two gregorian dates.
>
>Example 04/10/1992 - 04/08/1992 = 2 days.
>
>I am using the GregorianCalendar and it works fine as long as the dates 
>fall within the same year. However, if one of the dates is of a different 
>year ( e.g. -  04/10/1992 - 02/15/1991 ) the calculation does not work 
>correctly ..
>
>Does anyone out there have any ideas as to what I am doing wrong?



_______________________________________________
Juglist mailing list
[EMAIL PROTECTED]
http://trijug.org/mailman/listinfo/juglist_trijug.org

_______________________________________________
Juglist mailing list
[EMAIL PROTECTED]
http://trijug.org/mailman/listinfo/juglist_trijug.org

Reply via email to