开发者

Find the difference in days between a java.util.Date and a Joda-Time DateTime?

开发者 https://www.devze.com 2023-03-26 12:02 出处:网络
Is i开发者_C百科t possible to find the difference (preferably expressed in terms of the number of days) between a java.util.Date and a Joda-Time DateTime?

Is i开发者_C百科t possible to find the difference (preferably expressed in terms of the number of days) between a java.util.Date and a 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();
}


Just convert Date to DateTime and then use Days#daysBetween(). The DateTime has a constructor taking the time in millis and the Date has a getter returning exaclty that.

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

精彩评论

暂无评论...
验证码 换一张
取 消