Java 8 version based on user678573 answer :
private static String humanReadableFormat(Duration duration) { return String.format("%s days and %sh %sm %ss", duration.toDays(), duration.toHours() - TimeUnit.DAYS.toHours(duration.toDays()), duration.toMinutes() - TimeUnit.HOURS.toMinutes(duration.toHours()), duration.getSeconds() - TimeUnit.MINUTES.toSeconds(duration.toMinutes())); }
... since Java 8 does not have a PeriodFormatter and there are no methods like getHours, getMinutes, ...
I would be happy to see the best version for Java 8.
Torsten Jun 25 '18 at 14:37 2018-06-25 14:37
source share