I have two Date
objects with the below format.
SimpleDateFormat sdf = new SimpleDateFormat(\"yyyy-MM-dd\'T\'HH:mm:ss\");
String
Since Date
implements Comparable
, it is as easy as:
date1.compareTo(date2);
As the Comparable
contract stipulates, it will return a negative integer/zero/positive integer if date1
is considered less than/the same as/greater than date2
respectively (ie, before/same/after in this case).
Note that Date
has also .after()
and .before()
methods which will return booleans instead.