Compare two string Date using LocalDate class methods
package javaapplication;
import java.time.*;
import java.text.ParseException;
public class date {
public static void main(String[] args) throws ParseException {
String startDate = "2021-05-12";
String endDate = "2021-04-12";
LocalDate dateStart = LocalDate.parse(startDate);
LocalDate dateEnd = LocalDate.parse(endDate);
if (dateStart.isAfter(dateEnd)) {
System.out.println("Start Date is greater than End Date");
} else if (dateStart.isBefore(dateEnd)) {
System.out.println("Start Date is less than End Date");
} else {
System.out.println("Start Date is Equal to End Date");
}
}
}