Java Millisecond Convert toMillisToHHMMSSTime(long timeMillis)

Here you can find the source of toMillisToHHMMSSTime(long timeMillis)

Description

convert to hh:mm:ss

License

Apache License

Parameter

Parameter Description
timeMillis a parameter

Declaration

public static String toMillisToHHMMSSTime(long timeMillis) 

Method Source Code

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

public class Main {
    /**//  ww w  .j  a v  a 2  s.c o  m
     * convert to hh:mm:ss
     * 
     * @param timeMillis
     * @return
     */
    public static String toMillisToHHMMSSTime(long timeMillis) {
        String timeString = "";
        timeMillis = timeMillis / 1000;
        int days = (int) (timeMillis / 60 / 60 / 24);
        if (days > 0) {
            if (days < 10) {
                timeString += "0" + days + "-";
            } else {
                timeString += days + "-";
            }
        }
        int dayTime = days * 24 * 60 * 60;
        int hours = (int) ((timeMillis - dayTime) / 60 / 60);
        if (hours < 10) {
            timeString += "0" + hours + ":";
        } else {
            timeString += hours + ":";
        }

        int minutes = (int) ((timeMillis - dayTime - hours * 60 * 60) / 60);
        if (minutes < 10) {
            timeString += "0" + minutes + ":";
        } else {
            timeString += minutes + ":";
        }

        int seconds = (int) (timeMillis % 60);
        if (seconds < 10) {
            timeString += "0" + seconds;
        } else {
            timeString += seconds;
        }

        return timeString;
    }
}

Related

  1. toMilliseconds(long seconds, long nanos)
  2. toMilliseconds(Object value)
  3. toMillisFromNanos(long nanos)
  4. toMillisInfo(long ms)
  5. toMillisToDayTime(long mill)
  6. toMillisToKKMMSSTime(long mill)