The result of subtracting one date from another is not a date - in fact it's
pretty meaningless. This is not specific to java.

It depends what you want to get out - do you want the number of seconds between
the dates, milliseconds, days, hours, months etc?

For your problem (inactivity > 1 hour) something like the following will do:

if ( date1.getTime() - date2.getTime() > 1000 * 60 * 60 )
{
    //do something
}


You can get the same effect by using the Calendar class - this is generally
better practice since it does a lot of stuff to do with locales, and a lot of
the date stuff is now deprecated.


Denis Bucher wrote:

> Hello !
>
> My servlet opens a database connexion when started (in init()) only and I
> want him to close and reopen the connexion if inactivity is more than one
> hour. But HOW TO GET THE DIFFERENCE BETWEEN TWO DATES ???
>
>     java.util.Date datenow = new java.util.Date();
>     out.println("Date now : " + datenow.toString());
>     out.println("Last dbase access : " + datedb.toString());
>     datedb = new java.util.Date();
>
> And then ?????
>
>      new date = datedb - datenow ????
>
> And why do I have to say "java.util.Date" and not simply "Date" ???
>
> Denis
>
> --
>
> Denis Bucher,   /  [EMAIL PROTECTED]       T�l. +41-22-8000625   \  Internet
> Horus Networks /  horus-networks.com    Fax: +41-22-8000622   \  Services
>               /  http://www.horus.ch   US Fax: (508) 437-1261  \  Provider
>
> ___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

--
Tim Fox (��o)

Hyperlink plc
http://hyperlink.com

email: [EMAIL PROTECTED]
phone: +44 (0) 207 240 8121

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to