其他日期之间的日期java.time

时间:2015-07-06 15:52:18

标签: java java-8 java-time

如何使用Java 8的java.time API确定日期是否在两个其他日期之间?

1 个答案:

答案 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!");