I would like to calculate the number of the overlapping days between two date ranges. The 2 pairs of date ranges are read from the console in the format: yyyy-mm-dd
;
For example, if the two dates are
2020-01-05
2020-03-31
and
2020-01-05
2020-03-20
the program should find the days between 2020-01-05
and 2020-03-20
. However, it doesn't work. I would like to ask how can I fix this?
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.Scanner;
public class Dates {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String a = sc.nextLine();
String b = sc.nextLine();
String c = sc.nextLine();
String d = sc.nextLine();
LocalDate ldt1 = LocalDate.parse(a);
LocalDate ldt2 = LocalDate.parse(b);
LocalDate ldt3 = LocalDate.parse(c);
LocalDate ldt4 = LocalDate.parse(d);
System.out.println(ChronoUnit.DAYS.between(ldt1,ldt2,ldt3,ldt4));
}
}