Java Millisecond Convert millisecondsToHHMMSS(long milliseconds)

Here you can find the source of millisecondsToHHMMSS(long milliseconds)

Description

Convert a time in milliseconds to "hh:mm:ss" format.

License

Open Source License

Declaration

public static String millisecondsToHHMMSS(long milliseconds) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from w w w .ja  v  a 2  s .  c  om*/
     * Convert a time in milliseconds to "hh:mm:ss" format.
     */
    public static String millisecondsToHHMMSS(long milliseconds) {
        // convert from fraction of day to milliseconds
        long total = (milliseconds / 1000);
        long hours = total / 3600;
        total = total - (hours * 3600);
        long minutes = total / 60;
        total = total - (minutes * 60);
        long seconds = total;
        String sHours = hours + "";
        String sMinutes = minutes + "";
        String sSeconds = seconds + "";
        if (hours < 1) {
            sHours = "00";
        } else if (hours < 10) {
            sHours = "0" + sHours;
        }
        if (minutes < 1) {
            sMinutes = "00";
        } else if (minutes < 10) {
            sMinutes = "0" + sMinutes;
        }
        if (seconds < 1) {
            sSeconds = "00";
        } else if (seconds < 10) {
            sSeconds = "0" + sSeconds;
        }
        return sHours + ":" + sMinutes + ":" + sSeconds;
    }
}

Related

  1. getTimeString(long timelnMillis)
  2. getTimeTakenAsSecondsString(long timeTakenMillis)
  3. millisecondConvertToStringTime(final long milliseconds)
  4. millisecondsToDateTime(long timeMillis)
  5. millisecondsToDays(long p_timeInMilliseconds, long p_secondsInDay)
  6. milliSecondsToHMS(long l)
  7. milliSecondsToHMS(long numMillis)
  8. millisecondsToHuman(long ms)
  9. millisecondsToHumanDateWithSeconds(long milliseconds)