I am using jdatechooser
in Netbeans and I have two dates as output
date1 = 3/25/17
date2 = 3/30/17
I want a way of subtracting this two dates to get differece in days e.g: 3 Days
and put my results into a jtexftield
I am using jdatechooser
in Netbeans and I have two dates as output
date1 = 3/25/17
date2 = 3/30/17
I want a way of subtracting this two dates to get differece in days e.g: 3 Days
and put my results into a jtexftield
You can parse you date to LocaDate
and then calculate difference using Period
:
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("M/d/yy");
LocalDate start = LocalDate.parse("3/25/17",dateTimeFormatter);
LocalDate end = LocalDate.parse("3/30/17",dateTimeFormatter);
System.out.println(Period.between(start,end).getDays());
For pre java-8
code please see this question