Java Hour Format formatTime(long ms)

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

Description

Given elapsed time in milliseconds, return a string formatted HH:MM:SS

License

Open Source License

Declaration

public static String formatTime(long ms) 

Method Source Code

//package com.java2s;

public class Main {
    /** Given elapsed time in milliseconds,
    return a string formatted HH:MM:SS/*from  ww  w  . ja  v  a  2  s.co  m*/
    */
    public static String formatTime(long ms) {
        long h, m, s;
        s = ms / 1000; // ms -> seconds
        h = s / 3600; // hours
        s = s - (h * 3600);
        m = s / 60; // minutes
        s = s - (m * 60);
        s = (s > 0 ? s : 1); // round up to 1 second
        java.text.NumberFormat time = new java.text.DecimalFormat("00");
        return time.format(h) + ":" + time.format(m) + ":" + time.format(s);
    }
}

Related

  1. formatTime(final Date date)
  2. formatTime(final long time)
  3. formatTime(int msec, String format)
  4. formatTime(java.util.Date date)
  5. formatTime(long aTime)
  6. formatTime(long time)
  7. formatTime(long time)
  8. formatTime(long time)
  9. formatTime(long time, TimeUnit unit)