File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes how to determine if two Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Mongo DB Applied Patterns this week in the MongoDB forum
or a resume review from Five Year Itch in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "how to determine if two "Date" are same ?" Watch "how to determine if two "Date" are same ?" New topic
Author

how to determine if two "Date" are same ?

ben oliver
Ranch Hand

Joined: Mar 28, 2006
Posts: 369
If I create two java util Date objects, and set them to the same "real day", in JVM they are two different objects. But how do I tell if they actually contain the same "actual real day" ?
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 9939
    
    6

how about trying the equals() method of the Date class?


Never ascribe to malice that which can be adequately explained by stupidity.
Paul Beckett
Ranch Hand

Joined: Jun 14, 2008
Posts: 95
the equals method tests equality right down to the millisecond.

I've just been doing some date/time calculations recently and remembered very quickly how much of a pain the standard java implementations are.

If you are ok using other API's then something like DateUtils from apache commons lang may be of use. It contains an "isSameDay" method.

Other than that you will probably need to use the java.util.Calendar to produce a Date with the non relevant fields (hour/minute/second/millisecond) all set to zero. Then you should be able to do an equals comparison on your 2 'day only' dates.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: how to determine if two "Date" are same ?
 
Similar Threads
Short/Long day?
basic calendar questions
calculating times (please help!!)
about subtract dates
How to calculate two date