Comparing two Calendars
Author |
Message |
Einherjar
|
Posted: Sun Nov 16, 2008 9:04 pm Post subject: Comparing two Calendars |
|
|
I want to be able to calculate the number of days between the two dates, and what's the most efficient method?
I use this for the moment:
(int)(
(dueDate.getTimeInMillis() - Calendar.getInstance().getTimeInMillis())/ 86400000
)
I tried compareTo(), but it seems that it doesn't do what I wanted it to do. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
DemonWasp
|
Posted: Mon Nov 17, 2008 10:15 am Post subject: RE:Comparing two Calendars |
|
|
Your method will work, though it's worth noting that dividing by an integer in Java should yield an integer (rendering your (int) cast useless).
compareTo() is required by the Comparable interface, which allows you to use Collections.sort() on collections made of Comparables. It does not give the difference between two objects, just an overall ordering. |
|
|
|
|
|
Einherjar
|
Posted: Wed Nov 26, 2008 1:46 am Post subject: Re: Comparing two Calendars |
|
|
Ok, thanks.
I always thought that numbers were counted as double when it was put in an operation directly... |
|
|
|
|
|
|
|