- Instant help with your Java coding problems

Get the number of days between two dates in Java

Question:
How to get the number of days between two dates in Java?
Answer:
LocalDate start = LocalDate.parse("2020-11-03");
LocalDate end = LocalDate.parse("2020-12-15");

long diff = DAYS.between(start, end);
Description:

With Java 8 new java.time.temporal package it is fairly simple to get the number of days between two dates. Create a LocalDate object representation for the start and end dates. Then simply use the ChronoUnit.DAYS.between() method with the dates as parameter.

Share "How to get the number of days between two dates in Java?"