I am trying to calculate the difference between two LocalDateTime
.
The output needs to be of the format y years m months d days h hours m minutes
Here a single example using Duration and TimeUnit to get 'hh:mm:ss' format.
Duration dur = Duration.between(localDateTimeIni, localDateTimeEnd);
long millis = dur.toMillis();
String.format("%02d:%02d:%02d",
TimeUnit.MILLISECONDS.toHours(millis),
TimeUnit.MILLISECONDS.toMinutes(millis) -
TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(millis)),
TimeUnit.MILLISECONDS.toSeconds(millis) -
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis)));