Java TimeUnit Usage formatInterval(final long l)

Here you can find the source of formatInterval(final long l)

Description

Formatuje czas w milisekundach na czas w formacie HH:MM:SS:ss

License

Open Source License

Parameter

Parameter Description
l czas

Return

czas w formacie stringa

Declaration

public static String formatInterval(final long l) 

Method Source Code

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

import java.util.concurrent.TimeUnit;

public class Main {
    /**/*  ww w  .  j a v  a  2  s .c  o  m*/
     * Formatuje czas w milisekundach na czas w formacie HH:MM:SS:ss
     *
     * @param l czas
     * @return czas w formacie stringa
     */
    public static String formatInterval(final long l) {
        final long hr = TimeUnit.MILLISECONDS.toHours(l);
        final long min = TimeUnit.MILLISECONDS.toMinutes(l - TimeUnit.HOURS.toMillis(hr));
        final long sec = TimeUnit.MILLISECONDS
                .toSeconds(l - TimeUnit.HOURS.toMillis(hr) - TimeUnit.MINUTES.toMillis(min));
        final long ms = TimeUnit.MILLISECONDS.toMillis(
                l - TimeUnit.HOURS.toMillis(hr) - TimeUnit.MINUTES.toMillis(min) - TimeUnit.SECONDS.toMillis(sec));
        return String.format("%02d:%02d:%02d.%03d", hr, min, sec, ms);
    }
}

Related

  1. formatDurationTill(long start)
  2. formatElapsedSecs(long secs)
  3. formatElapsedTime(final long seconds)
  4. formatElapsedTime(long elapsedTimeMs)
  5. formatElapsedTime(long millis)
  6. formatMillis(final long millis)
  7. formatMillis(final long millis)
  8. formatMillis(long millis)
  9. formatMillis(long millis)