Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Comparing two Calendars
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Einherjar




PostPosted: 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
Sponsor
sponsor
DemonWasp




PostPosted: 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




PostPosted: 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...
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: