Hi Eric,

simply keep in mind that Calendar.getInstance() gets a Calender instance (in fact a 
GregorianCalender one) with the current date.
This does not imply day, month & year but also hours, minutes, seconds & milliseconds!

So each time you call getInstance() you will get the current time in milliseconds 
also. Therefore if you are only interested in differences in days and not milliseconds 
you will have to use either the same object (get one instance and clone it) or make 
sure that the time part in your calender object is the same (e.g. 00:00:00.000).

Regards,
Stefan.

"Shiau, Eric" wrote:

> Curious,
>
> But both programs do not set time.  Shouldn't it behave the same?  Shouldn't
> its output be the same?
>
> > -----Original Message-----
> > From: Rudy Gireyev [SMTP:[EMAIL PROTECTED]]
> > Sent: Wednesday, February 07, 2001 12:56 PM
> > To:   Shiau, Eric; '[EMAIL PROTECTED]'
> > Subject:      RE: Help: Date Difference
> >
> > You are only setting the date and not the time.
> > That accounts for the difference.
> >
> > Also, you can use the following list for non Swing
> > questions if you like. Send INFO JAVA to
> > [EMAIL PROTECTED]
> >
> > Rudy
> >
> >
> > -----Original Message-----
> > From: Shiau, Eric [mailto:[EMAIL PROTECTED]]
> > Sent: Wednesday, February 07, 2001 8: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
>
> ------------------------------------------------------------------------------
> 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