Java Millisecond Convert millisToTime(long ms)

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

Description

milliseconds to day hour:min:ss

License

Apache License

Parameter

Parameter Description
ms a parameter

Declaration

public final static String millisToTime(long ms) 

Method Source Code

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

public class Main {
    /**//from   w  ww . j a  v  a  2  s.c  om
     * milliseconds to day hour:min:ss
     * @param ms
     * @return
     */
    public final static String millisToTime(long ms) {
        int ss = 1000;
        int mi = ss * 60;
        int hh = mi * 60;
        int dd = hh * 24;
        long day = ms / dd;
        long hour = (ms - day * dd) / hh;
        long minute = (ms - day * dd - hour * hh) / mi;
        long second = (ms - day * dd - hour * hh - minute * mi) / ss;
        long milliSecond = ms - day * dd - hour * hh - minute * mi - second * ss;
        String strDay = day < 10 ? "0" + day : "" + day;
        String strHour = hour < 10 ? "0" + hour : "" + hour;
        String strMinute = minute < 10 ? "0" + minute : "" + minute;
        String strSecond = second < 10 ? "0" + second : "" + second;
        String strMilliSecond = milliSecond < 10 ? "0" + milliSecond : "" + milliSecond;
        strMilliSecond = milliSecond < 100 ? "0" + strMilliSecond : "" + strMilliSecond;
        return strDay + " " + strHour + ":" + strMinute + ":" + strSecond + " " + strMilliSecond;
    }
}

Related

  1. millisToString(long t)
  2. millisToStringDouble(double millis)
  3. millisToText(long millis)
  4. millisToTime(final long time)
  5. millisToTime(float millis)
  6. millisToTimeSpan(final long interv)
  7. millisToTimeSpan(long millis)
  8. MillisToTimeString(long millis)
  9. millisToWords(long millis)