Here is the example to compare 2 string format dates :
String dateOneStr = "12/02/2016";
String dateTwoStr = "13/02/2016";
Date date1,date2;
DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
try {
date1 = df.parse(dateOneStr);
date2 = df.parse(dateTwoStr);
if(date1.after(date2)){
System.out.println("Date1 is after Date2");
}
if(date1.before(date2)){
System.out.println("Date1 is before Date2");
}
if(date1.equals(date2)){
System.out.println("Date1 is equal Date2");
}
} catch (ParseException e) {
e.printStackTrace();
}
No comments:
Post a Comment