Java date, time comparison
using the Joda package
Date Comparison
String begindate = "2017/07/05";
String enddate = "2017/09/04";
SYSTEM.OUT.PRINTLN (new DateTime (Begindate). Isafter (new DateTime (EndDate)); The result is false
String begindate = "2017/09/04";
String enddate = "2017/09/04";
SYSTEM.OUT.PRINTLN (new DateTime (Begindate). Isafter (new DateTime (EndDate)); The result is false
String begindate = "2017/07/05";
String enddate = "2017/09/04";
SYSTEM.OUT.PRINTLN (new DateTime (Begindate). Isbefore (new DateTime (EndDate)); The result is true
String begindate = "2017/09/04";
String enddate = "2017/09/04";
SYSTEM.OUT.PRINTLN (new DateTime (Begindate). Isbefore (new DateTime (EndDate)); The result is false
Time Comparison
String begintime = "15:02:22";
String endtime = "15:02:22";
System.out.println (New LocalTime (BeginTime). CompareTo (New LocalTime (Endtime)); The result is 0
String begintime = "12:02:22";
String endtime = "15:02:22";
System.out.println (New LocalTime (BeginTime). CompareTo (New LocalTime (Endtime)); The result is-1
String begintime = "12:02:22";
String endtime = "10:02:22";
System.out.println (New LocalTime (BeginTime). CompareTo (New LocalTime (Endtime)); Result is 1
using the SimpleDateFormat package
Date and Time comparisons
string begintime = "10:00:00";
String endtime = "3:59:59";
StringBuilder datebegin = new StringBuilder ("2018-08-08");
StringBuilder dateend = new StringBuilder ("2018-08-08");
Date dtbegintime = Df.parse (Datebegin.append (begintime). toString ());
Date dtendtime = Df.parse (Dateend.append (Endtime). toString ()); System.out.println (Dtbegintime.gettime () >= dtendtime.gettime ()); True System.out.println (dtbegintime.gettime () = = Dtendtime.gettime ()); False System.out.println (Dtbegintime.gettime () < Dtendtime.gettime ()); False