Compare two dates

I'd like to know how to compare two dates to knowthe number of days and hours beetwing them.Regars . Thanks
[136 byte] By [fribro] at [2007-9-26 3:54:02]
# 1

Cheesy quick way of doing it is to subtract their time values from each other.

You can then work out number of hours by dividing by (60x60x1000) and days in a similar way.

long difference = date2.getTime() - date1.getTime();

int days = difference / (24 * 60 * 60 * 1000);

difference -= days * (24 * 60 * 60 * 1000);

int hours = difference / (60 * 60 * 1000);

It should suffice.

KPSeal at 2007-6-29 12:42:50 > top of Java-index,Archived Forums,Portability & Platform Independence [Archive]...
# 2
Thanks,I'll try.
fribro at 2007-6-29 12:42:50 > top of Java-index,Archived Forums,Portability & Platform Independence [Archive]...