1
我刚开始查看JODA库,并且想要获取当前时间并查看它是否落在DB中的时间戳记的3天内。使用DateTime将当前日期与另一日期进行比较
我在看他们的API的例子:
public boolean isRentalOverdue(DateTime datetimeRented) {
Period rentalPeriod = new Period().withDays(2).withHours(12);
return datetimeRented.plus(rentalPeriod).isBeforeNow();
}
我以一个字符串从数据库中创建一个Date对象:
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = (Date)formatter.parse(startDate);
我如何可以看到,如果Date对象在我的代码在当前时间3天内?:
Period threeDays = new Period().withDays(3);
boolean withinThreeDays = date.plus(threeDays).isBeforeNow();
改为isAfterNow()和它的工作100%。感谢这些信息,非常感谢。 – user82302124