Java Time Readable Format toTime(long ms)

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

Description

Turn the input long into a string on the form (D:)HH:MM:SS, where the day-part is only added if the number of days is greater than or equal to 1, i.e.

License

Open Source License

Parameter

Parameter Description
ms time in milliseconds

Return

string-representation of the input long

Declaration

public static String toTime(long ms) 

Method Source Code

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

public class Main {
    /**//from   w  w w  .ja  va  2  s  . co  m
     * Turn the input long into a string on the form (D:)HH:MM:SS, where the
     * day-part is only added if the number of days is greater than or equal
     * to 1, i.e. a long value of 86,399,999.
     * @param ms time in milliseconds
     * @return string-representation of the input long
     */
    public static String toTime(long ms) {
        long total = ms / 1000;
        long secs = total % 60;
        long mins = total % 3600 / 60;
        long hours = total / 3600 % 24;
        long days = total / 3600 / 24;
        String time = (days > 0 ? days + ":" : "") + (hours < 10 ? "0" + hours : hours) + ":"
                + (mins < 10 ? "0" + mins : mins) + ":" + (secs < 10 ? "0" + secs : secs);
        return time;
    }
}

Related

  1. humanTime(long ms)
  2. humanTime(long seconds)
  3. humanTime(long start, long end)
  4. toHumanable(long time_millsecod)
  5. toTime(int duration)
  6. toTime(long nanos)
  7. toTime(long time)
  8. toTime2(int value, int nanos, int meta)
  9. toTimeExpression(long ms, int frames)