Java Duration Format formatDuration(final Duration duration)

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

Description

format Duration

License

Open Source License

Declaration

public static String formatDuration(final Duration duration) 

Method Source Code

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

Related

  1. formatDuration(Duration duration)
  2. formatDuration(Duration duration)
  3. formatDuration(Duration duration)
  4. formatDuration(Duration duration)
  5. formatDuration(Duration duration, boolean inProgress)
  6. formatDuration(final Duration duration, final boolean wrapInDurationFunction)
  7. formatDuration(final int duration)
  8. formatDuration(final long milliSeconds)
  9. formatDuration(final long seconds)