Java Duration Format formatDuration(Duration duration)

Here you can find the source of formatDuration(Duration duration)

Description

Formats a Duration.

License

Open Source License

Parameter

Parameter Description
duration a duration of time

Return

String in MM:SS format

Declaration

public static String formatDuration(Duration duration) 

Method Source Code


//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;
    }
}

Related

  1. formatBuildDuration(final long duration)
  2. formatDuration(double dblSeconds)
  3. formatDuration(Duration d)
  4. formatDuration(Duration duration)
  5. formatDuration(Duration duration)
  6. formatDuration(Duration duration)
  7. formatDuration(Duration duration)
  8. formatDuration(Duration duration, boolean inProgress)
  9. formatDuration(final Duration duration)