• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Comparison between two dates

 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 miss the old days when I would think up a sinister scheme for world domination and you would show a little emotional support. So just look at this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic