Java Duration Format formatDuration(Duration duration)

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

Description

format Duration

License

Apache License

Declaration

private static String formatDuration(Duration duration) 

Method Source Code


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

Related

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