Here you can find the source of formatDuration(Duration duration)
private static String formatDuration(Duration duration)
//package com.java2s; //License from project: Apache License import java.time.Duration; import java.time.temporal.ChronoUnit; public class Main { private static String formatDuration(Duration duration) { long hours = Math.abs(duration.toHours()); long minutes = Math.abs(duration.minus(duration.toHours(), ChronoUnit.HOURS).toMinutes()); long seconds = Math.abs(duration.minus(duration.toMinutes(), ChronoUnit.MINUTES).getSeconds()); final String f = String.format("%02d:%02d:%02d", hours, minutes, seconds); return f; }/*from w w w. ja va 2 s .co m*/ }