Java Time Format formatTime(long millis)

Here you can find the source of formatTime(long millis)

Description

format Time

License

Open Source License

Declaration

public static String formatTime(long millis) 

Method Source Code

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

public class Main {
    public static String formatTime(long millis) {
        long secs = millis / 1000;
        long s = secs % 60;
        long m = (secs / 60) % 60;
        long h = secs / 3600 % 24;
        long d = secs / (3600 * 24);
        StringBuilder sb = new StringBuilder();
        if (d > 0)
            sb.append(d + "d ");
        if (d > 0 || h > 0)
            sb.append(h + "h ");
        if (d > 0 || m > 0 || h > 0)
            sb.append(m + "m ");
        sb.append(s + "s");

        return sb.toString();
    }/* w ww  . j a  va2s. co m*/
}

Related

  1. formatTime(long dtNanos)
  2. formatTime(long elapsedTime)
  3. formatTime(long elapsedTime)
  4. formatTime(long millis)
  5. formatTime(long millis)
  6. formatTime(long millis)
  7. formatTime(long millis, int precision)
  8. formatTime(long ms)
  9. formatTime(long ms)