user1730789
user1730789

Reputation: 5177

Difference between two dates using the JODA Library

I have two DateTime instances and i would like to find out the exact difference between them. I am using the following

DateTime dt = DateUtils.convertFromString(user.getUpdated());
DateTime now = DateTime.now();
Hours hours = Hours.hoursBetween(now, dt);

This off course only gives me the Hours between the two dates. I need the complete values like X Day y hours and z minutes. How can i do this ?

Upvotes: 1

Views: 356

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1499770

Use Period:

Period period = new Period(now, dt);

You can provide a PeriodType which specifies exactly which units you want.

(If dt was in the past, you probably actually want new Period(dt, now) instead, to give a positive period.)

Upvotes: 1

Related Questions