Reputation: 67
could everyone help me with if statement below so that it will be true when the date in the GregorianCalendar instance myGC1 is not later than the date of the GregorianCalendar instance myGC2:
if ( ) {
...
}
Upvotes: 0
Views: 651
Reputation: 44250
Use the inherited Calendar
method after
if(!myGC1.after(myGC2)){
// do stuff
}
Also, according to the API, this method is equivalent to compareTo
if(!(myGC1.compareTo(myGC2) > 0)){
// do stuff
}
Upvotes: 4
Reputation: 7695
if ( !(myGC1.compareTo(myGC2)>0) )
{
...
}
Using the compareTo method will allow you to check for equality as well as >,<.
Upvotes: 0
Reputation: 5582
I prefer Joda. It makes datetime comparison very straightforward and easy without having to deal with calendar specifics.
DateTime firstDate = ...;
DateTime secondDate = ...;
return firstDate.compareTo(secondDate);
Upvotes: 0
Reputation: 324
The following should work.
if ( !gc2.after(gc) )
{
// then the date is not after gc1.. do something
}
Upvotes: 1