Here you can find the source of formatDuration(Duration duration)
Parameter | Description |
---|---|
duration | a duration of time |
public static String formatDuration(Duration duration)
//package com.java2s; //License from project: Open Source License import java.time.Duration; public class Main { /**//from ww w. j a va 2s . c o m * Formats a Duration. Code modified from http://stackoverflow.com/a/266846 * @param duration a duration of time * @return String in MM:SS format */ public static String formatDuration(Duration duration) { long seconds = duration.getSeconds(); long absSeconds = Math.abs(seconds); String positive = String.format("%02d:%02d", // absSeconds / 3600, (absSeconds /*% 3600*/) / 60, absSeconds % 60); return seconds < 0 ? "-" + positive : positive; } }