This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Comparison between two dates Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Comparison between two dates" Watch "Comparison between two dates" New topic
Author

Comparison between two dates

vidhya subramaniam
Ranch Hand

Joined: Jul 14, 2001
Posts: 91
I have one date as
String s = message[i].getSentDate().toString()
and another one is
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE,-1);
SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd 'at' 14:00:00");
fmt.format(cal.getTime());
I want to put fmt.format(cal.getTime()) in a variable and compare it with s. I would like to know if the date is less or greater than the other.
Whats the best way to do it
Thanks,
Vidhya
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
The Calendar class has all sorts of methods for comparing two dates. So I would convert my string into a Calendar and then do the comparison.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Nayanjyoti Talukdar
Ranch Hand

Joined: Feb 12, 2002
Posts: 71
I suggest to convert both the object to Date object. Date class implements Comparable interface which has a method called compareTo(Object o). Using the method, one can compare two Date object.
--------------
Nayan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Comparison between two dates
 
Similar Threads
How to get the timestamp from the File IO
Date
Calendar class
SimpleDateFormatter shows wrong hour?
Today(Yes), Tomorrow(No), Date realated problem.