0

I am wondering if there is a library one can use that calculates elapsed time? Something like... if you pass it a long of milliseconds, you get a result like "2d 5h 12m 55s" (possibly even more formats similarly to SimpleDateFormatter).

I've heard of jodatime, but I've never used it. Can it be used for such calculations, or are there other more appropriate libraries?

It's not like I can't knock up a few methods myself, but I find myself doing this every now and then and that's why I'm wondering if something like this already exists.

carlspring
  • 31,231
  • 29
  • 115
  • 197
  • 1
    http://stackoverflow.com/questions/625433/how-to-convert-milliseconds-to-x-mins-x-seconds-in-java – Forte L. Jun 25 '12 at 15:29
  • 3
    I believe that the answer you are looking for is in this ancient post: http://stackoverflow.com/questions/567659/calculate-elapsed-time-in-java-groovy – rlinden Jun 25 '12 at 15:30
  • 1
    Possible duplicate of [How do I calculate the elapsed time of an event in java?](http://stackoverflow.com/questions/238920/how-do-i-calculate-the-elapsed-time-of-an-event-in-java) – Steve Chambers Nov 06 '15 at 11:44
  • @SteveChambers That question doesn't cover converting the elapsed time to days, hours, minutes, etc. – Kenster Nov 06 '15 at 13:33

1 Answers1

3

Use Joda time's Period & PeriodFormatter. Example.

Community
  • 1
  • 1
Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228