Run your second Try several times in a row and you'll notice that it changes
back and forth between 364 and 365.

Here's what is going on:
  *getTime() the milliseconds since January 1, 1970, 00:00:00 GMT.
  *There is a slight delay between your 2 calls of getInstance. On my PC,
this delay
   is up to 10 milliseconds.
  *When the PC does not have a delay, the result of the subtraction is
31536000000.
  *When the PC does have a delay, the result of the subtraction is
31535999990.
  *31536000000 / 86400000 = 365
  *31535999990 / 86400000 = 364.999999
  *(long)364.999999 = 364

You need to round your result (days) up. I'm not sure what the simplest way
to do this is (and it's lunch time)!

Brian


-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of Shiau,
Eric
Sent: Wednesday, February 07, 2001 10:09 AM
To: '[EMAIL PROTECTED]'
Subject: Help: Date Difference


> I wrote a date difference programs.  However, two programs give me
> different results? one day difference, why? Program 1, show me output as
> 365; Program 2, show me 364.
>
> Both programs are identical except Program 2, embedded yy, mm, dd on the
> Calendar.set()  method.
>
>
> Program 1:
> import java.util.*;
>
> public class Try {
>   public static void main(String[] arg) {
>   String ddd = "02/07/02";
>     int yy = 2000 + Integer.parseInt(ddd.substring(6,8));
>     int mm = Integer.parseInt(ddd.substring(0,2)) - 1;
>     int dd = Integer.parseInt(ddd.substring(3,5));
>     System.out.println(yy + " " + mm + " " + dd);
>   Calendar mat = Calendar.getInstance();
>     mat.set(yy, mm, dd);
>   Calendar now = Calendar.getInstance();
>   long days = (mat.getTime().getTime() - now.getTime().getTime()) /
> 86400000L;
>     System.out.println(days);
>   }
> }
>
> Program 2:
> import java.util.*;
>
> public class Try {
>   public static void main(String[] arg) {
>   String ddd = "02/07/02";
>   Calendar mat = Calendar.getInstance();
>     mat.set(2000 + Integer.parseInt(ddd.substring(6,8)),
>       Integer.parseInt(ddd.substring(0,2)) - 1,
>       Integer.parseInt(ddd.substring(3,5)));
>   Calendar now = Calendar.getInstance();
>   long days = (mat.getTime().getTime() - now.getTime().getTime()) /
> 86400000L;
>     System.out.println(days);
>   }
> }



----------------------------------------------------------------------------
--
This message is intended only for the personal and confidential use of the
designated recipient(s) named above.  If you are not the intended recipient
of this message you are hereby notified that any review, dissemination,
distribution or copying of this message is strictly prohibited.  This
communication is for information purposes only and should not be regarded as
an offer to sell or as a solicitation of an offer to buy any financial
product, an official confirmation of any transaction, or as an official
statement of Lehman Brothers Inc.  Email transmission cannot be guaranteed
to be secure or error-free.  Therefore, we do not represent that this
information is complete or accurate and it should not be relied upon as
such.  All information is subject to change without notice.


_______________________________________________
Swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/swing


_______________________________________________
Swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/swing

Reply via email to