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.
Reference:
ChronoUnit.DAYS between reference
Share "How to get the number of days between two dates in Java?"
Related snippets:
- Get the last Friday of a month in Java
- Get the first Monday of a month in Java
- Get the first day of the week in Java
- Get the first day of the current month in Java
- Get the last day of a month in Java
- Get the number of days between two dates in Java
- Get yesterday's date in Java
- Get tomorrow's date in Java
- Get actual date in Java
Tags:
number of days between two dates, difference between two dates, days between dates, java Technical term:
Get the number of days between two dates in Java