Two variables of the date type can be compared by the CompareTo method. The description of this method is this: if the parameter date equals this date, the value 0 is returned, and if this date precedes the date parameter, a value less than 0 is returned, and if this date is after the date parameter, a value greater than 0 is returned.
The actual comparison is the number of milliseconds since January 1, 1970 00:00:00 GMT. The greater the number of milliseconds the greater the time.
String DateStr1 = "2014-08-21 10:20:16";
String DateStr2 = "2014-08-27 15:50:35";
DateFormat DateFormat = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");
Date dateTime1 = Dateformat.parse (DATESTR1);
Date dateTime2 = Dateformat.parse (DATESTR2);
int i = Datetime1.compareto (dateTime2);
System.out.println (i < 0);
JAVA Date Type Data comparison sizing method