Friday 29 November 2019

Is there a Java library for calculating elapsed time?



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.


Answer



Use Joda time's Period & PeriodFormatter. Example.


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...