When comparing two dates with date before method, if the dates are similar, it returns false as follows:
- date1: Tue Dec 18 00:00:00 GMT+02:00 2012
- date2: Tue Dec 18 00:00:00 GMT+02:00 2012
the method date1.before(date2) always returns false in this case, which does not make sense to me (doesn’t apply to my case in other words).
I want to check if a date (day/month/year) equals today’s date (day/month/year)?
As
date1.equals(date2), it is normal thatdate1.before(date2)returnsfalse. As will dodate1.after(date2).Both dates are the same, so one is not before the other.
From the javadoc :
Try something like:
The answers provided below suggest testing for the inverse, and they’re right:
Both tests are equivalent.