Duration is used to represent a time difference in hours, minutes, and seconds. It’s particularly useful for measuring short durations or elapsed time.
Source Code
LocalTime startTime = LocalTime.of(8, 30);
LocalTime endTime = LocalTime.of(12, 45);
Duration duration = Duration.between(startTime, endTime);
System.out.println("Duration: " + duration.toHours() + " Hour(s) "
+ duration.toMinutesPart() + " Minute(s)");