【发布时间】:2016-06-02 20:11:35
【问题描述】:
我有一个java.util.Date,我需要检查它是否超过 30 天。最好的检查方法是什么?
for(Date date: listOfDates) {
// how to check this date to see whether it is more than 30 days limit
if(checkDateLimit()) {
}
}
我使用的是 Java 7。
【问题讨论】:
-
您可以使用 this 之类的方法计算过去 30 天的日期,然后确定指定日期是在它之前还是之后
-
getTime() 将帮助您以很少的计算来比较日期。
-
@david 发帖前请搜索 Stack Overflow。