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,608
  • 7
  • 31
  • 45
user1730789
  • 5,157
  • 8
  • 36
  • 57

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,421,763
  • 867
  • 9,128
  • 9,194