1

In java.util.Date the function after() == ">"

Is there a way to compare dates as ">=" ?

0

5 Answers 5

10

How about using

!thisDate.before(thatDate) 

to implement the ">=" function. Not hugely nice, I appreciate.

Sign up to request clarification or add additional context in comments.

Comments

2

What about "not before"?

boolean result = !date.before(otherDate)

Also, Joda Time can save you a lot of time :)

Comments

1

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.

Comments

0

if (!date.before(otherdate) - has the same effect as " not after or equal to"

Comments

0

No ....Java does not support that...instead you can use

Date#equals() and Date#after()

I too also prefer Joda Time

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.