Java Long Number Format format(long ms)

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

Description

Transform the time in milliseconds to the time in "dd hh:mm:ss.SSS" format.

License

Open Source License

Parameter

Parameter Description
ms milliseconds

Return

dd hh:mm:ss.SSS

Declaration

public static String format(long ms) 

Method Source Code

//package com.java2s;

public class Main {
    /**//w  w w  .j ava 2  s.co  m
     * Transform the time in milliseconds to the time in "dd hh:mm:ss.SSS"
     * format.
     * 
     * @param ms milliseconds
     * @return dd hh:mm:ss.SSS
     */
    public static String format(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 new StringBuffer(strDay).append(" ").append(strHour).append(":").append(strMinute).append(":")
                .append(strSecond).append(".").append(strMilliSecond).toString();
    }
}

Related

  1. format(final long value, final long divider, final String unit)
  2. format(final long value, final long divider, final String unit)
  3. format(long bytes)
  4. format(long mem)
  5. format(long milliseconds)
  6. format(long numero, int numeroZeri)
  7. format(long offsetMillis)
  8. format(long s)
  9. format(long seconds)