Here you can find the source of formatDuration(final Duration duration)
public static String formatDuration(final Duration duration)
//package com.java2s; //License from project: Open Source License import java.time.*; public class Main { public static String formatDuration(final Duration duration) { long absSeconds = Math.abs(duration.getSeconds()); long seconds = absSeconds % 60; long minutes = (absSeconds % 3600) / 60; long hours = absSeconds / 3600; return (hours == 0 ? "" : hours + ":") + (minutes == 0 ? "00" : minutes < 10 ? String.valueOf("0" + minutes) : String.valueOf(minutes)) + ":" + (seconds == 0 ? "00" : seconds < 10 ? String.valueOf("0" + seconds) : String.valueOf(seconds)); }/* w w w . j av a 2 s.co m*/ }