Java TimeUnit Usage formatMillis(final long millis)

Here you can find the source of formatMillis(final long millis)

Description

format Millis

License

Open Source License

Declaration

public static String formatMillis(final long millis) 

Method Source Code

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

import java.util.concurrent.TimeUnit;

public class Main {
    public static String formatMillis(final long millis) {
        long seconds = TimeUnit.MILLISECONDS.toSeconds(millis)
                - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis));
        long minutes = TimeUnit.MILLISECONDS.toMinutes(millis)
                - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(millis));
        long hours = TimeUnit.MILLISECONDS.toHours(millis);

        return (hours == 0 ? "00" : hours < 10 ? String.valueOf("0" + hours) : String.valueOf(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));
    }//from  w ww.ja  va 2  s.  co m
}

Related

  1. formatElapsedSecs(long secs)
  2. formatElapsedTime(final long seconds)
  3. formatElapsedTime(long elapsedTimeMs)
  4. formatElapsedTime(long millis)
  5. formatInterval(final long l)
  6. formatMillis(final long millis)
  7. formatMillis(long millis)
  8. formatMillis(long millis)
  9. formatMillisecs(long lMillisecs, final boolean bWantMSecs)