How do you determine if a date is between two other dates with Java 8's java.time
API?
Asked
Active
Viewed 4,695 times
-6

Basil Bourque
- 303,325
- 100
- 852
- 1,154

Matthias M
- 135
- 3
- 19
-
What research have you done with the API on the JavaDoc site? – AlBlue Jul 06 '15 at 16:36
1 Answers
8
The LocalDate
class has
isAfter(LocalDate other)
isBefore(LocalDate other)
isEqual(LocalDate other)
methods for comparisons with other dates. Here is an example:
LocalDate today = LocalDate.now();
LocalDate tomorrow = LocalDate.now().plusDays(1);
LocalDate yesterday = LocalDate.now().minusDays(1);
if(today.isAfter(yesterday) && today.isBefore(tomorrow))
System.out.println("Today is... today!");

AlBlue
- 23,254
- 14
- 71
- 91

Luigi Cortese
- 10,841
- 6
- 37
- 48