Reputation: 394
In java.util.Date
the function after()
== ">"
Is there a way to compare dates as ">=" ?
Upvotes: 1
Views: 10854
Reputation: 11433
Date
implements Comparable
, so you can use the compareTo
method:
if (date.compareTo(otherdate) >= 0) { ... }
Basically compareTo
is the Java way for comparing objects with >
, <=
etc. and works in lots of circumstances. The after
and before
methods of Date
probably exist only because they were introduced before compareTo
was added.
Upvotes: 1
Reputation: 20741
No ....Java does not support that...instead you can use
Date#equals()
and Date#after()
I too also prefer Joda Time
Upvotes: 0
Reputation: 4923
What about "not before"?
boolean result = !date.before(otherDate)
Also, Joda Time can save you a lot of time :)
Upvotes: 2
Reputation: 32670
if (!date.before(otherdate)
- has the same effect as " not after or equal to"
Upvotes: 0
Reputation: 272217
How about using
!thisDate.before(thatDate)
to implement the ">=" function. Not hugely nice, I appreciate.
Upvotes: 10