I know there are lots of questions on SO about how to get Dates in Java, but I want an example using new Java 8 Date API. I also know about the JodaTime library, but I want a method without relying on external libraries.
The function needs to be compliant with these restrictions:
- Prevent errors from date savetime
- Inputs are two
Dateobjects (without time, I know aboutLocalDateTime, but I need to do this withDateinstances)
If you want logical calendar days, use
DAYS.between()method fromjava.time.temporal.ChronoUnit:If you want literal 24 hour days, (a duration), you can use the
Durationclass instead:For more information, refer to this document: Java SE 8 Date and Time.