Java TimeUnit Usage format(long elapsed, boolean hours)

Here you can find the source of format(long elapsed, boolean hours)

Description

format

License

Open Source License

Declaration

private static String format(long elapsed, boolean hours) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.concurrent.TimeUnit;

public class Main {
    private static String format(long elapsed, boolean hours) {
        final long hr = TimeUnit.MILLISECONDS.toHours(elapsed);
        final long min = TimeUnit.MILLISECONDS.toMinutes(elapsed - TimeUnit.HOURS.toMillis(hr));
        final long sec = TimeUnit.MILLISECONDS
                .toSeconds(elapsed - TimeUnit.HOURS.toMillis(hr) - TimeUnit.MINUTES.toMillis(min));
        return hours ? String.format("%02d:%02d:%02d", hr, min, sec) : String.format("%02d:%02d", min, sec);
    }// www  . j  av a 2  s .  com
}

Related

  1. durationToString(long duration)
  2. durationToString(long millis)
  3. elapsedMicroSec(long startNanoTime)
  4. elapsedTime(long start, long end)
  5. elapsedTimeSince(Date d)
  6. formatDuration(long duration)
  7. formatDuration(long millis)
  8. formatDuration(long millis)
  9. formatDuration(long time)