找出java.util.Date和Joda-Time DateTime之间的天数差异?

时间:2011-08-04 18:16:55

标签: java date jodatime

是否有可能找到java.util.Date和Joda-Time DateTime之间的差异(最好以天数表示)?

class ReminderInterval{
    //it will return a last login date(java.util.Date)
    Date lastDate=Obj.getAccepted();

    //it is Joda-Time type
    DateTime currentDate=new DateTime();
}

1 个答案:

答案 0 :(得分:5)

只需将Date转换为DateTime,然后使用Days#daysBetween()即可。 DateTimeconstructor花费时间以毫秒为单位,而Dategetter返回exaclty。

DateTime lastDate = new DateTime(Obj.getAccepted().getTime());
DateTime currentDate = new DateTime();
int days = Days.daysBetween(lastDate, currentDate).getDays();