如何使用Java 8的java.time
API确定日期是否在两个其他日期之间?
答案 0 :(得分:7)
LocalDate
班有
isAfter(LocalDate other)
isBefore(LocalDate other)
isEqual(LocalDate other)
与其他日期进行比较的方法。这是一个例子:
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!");