Java Time Format formatTime(long millis)

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

Description

format Time

License

Open Source License

Declaration

static String formatTime(long millis) 

Method Source Code

//package com.java2s;

public class Main {
    static final int MILLIS = 1000;
    static final int SECONDS = MILLIS;
    static final int MINUTES = 60 * SECONDS;
    static final int HOURS = 60 * MINUTES;

    static String formatTime(long millis) {
        StringBuffer sb = new StringBuffer();
        long n = millis / HOURS;

        if (n != 0) {
            sb.append(n).append("h");
        }/*w w w.  j a v  a  2s.co  m*/

        n = (millis % HOURS) / MINUTES;

        if ((n) != 0) {
            sb.append(n).append("m");
        }

        sb.append((millis % MINUTES) / SECONDS).append(".");

        n = millis % MILLIS;

        if (n < 100)
            sb.append("0");
        if (n < 10)
            sb.append("0");

        sb.append(n).append("s");

        return (sb.toString());
    }
}

Related

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