The signature of ChronoUnit.DAYS.between method
is:
public long between(Temporal temporal1Inclusive, Temporal temporal2Exclusive)
So the last date is not included as it relates the example:
LocalDate from = LocalDate.now();
LocalDate to = from.plusDays(1);
ChronoUnit.DAYS.between(from, to); // Result is 1
Is there another function to get 2 days in that expression?
Otherwise I only see that I could do that as the following:
LocalDate from = LocalDate.now();
LocalDate to = from.plusDays(1);
ChronoUnit.DAYS.between(from, to.plusDays(1)); // Result is 2
To calculate the days between two dates we can use the DAYS. between() method of java. time. temporal.
Actually NO, but you can use the following code:
ChronoUnit.DAYS.between(from, to) + 1;
+1
adds 1 day to the difference between those two local dates so we can say that the last date is included.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With