1

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 ?

John Willemse
  • 6,508
  • 7
  • 30
  • 44
user1730789
  • 5,077
  • 7
  • 33
  • 54

1 Answers1

1

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.)

Jon Skeet
  • 1,335,956
  • 823
  • 8,931
  • 9,049