Java Time Format formatTime(long timeDiffMillis)

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

Description

format Time

License

Apache License

Declaration

public static String formatTime(long timeDiffMillis) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static String formatTime(long timeDiffMillis) {
        StringBuilder buf = new StringBuilder();
        long hours = timeDiffMillis / (60 * 60 * 1000);
        long rem = (timeDiffMillis % (60 * 60 * 1000));
        long minutes = rem / (60 * 1000);
        rem = rem % (60 * 1000);/*from   w w w . j  a  v a  2s  . com*/
        long seconds = rem / 1000;

        if (hours != 0) {
            buf.append(hours);
            buf.append("h");
        }
        if (hours != 0 || minutes != 0) {
            if (buf.length() > 0) {
                buf.append(" ");
            }
            buf.append(minutes);
            buf.append("m");
        }
        if (buf.length() > 0) {
            buf.append(" ");
        }
        buf.append(seconds).append("s");
        return buf.toString();
    }
}

Related

  1. formatTime(long time)
  2. formatTime(long time)
  3. formatTime(long time, String syntax, boolean extraZeros)
  4. formatTime(long timeDiff)
  5. formatTime(long timeDiff)
  6. formatTime(long timeInMilli)
  7. formatTime(long timeInSecond)
  8. formatTime(long timeInterval, int maxTerms)
  9. formatTime(long timeMillis)