Java Time Readable Format humanTime(long ms)

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

Description

human Time

License

Apache License

Declaration

static String humanTime(long ms) 

Method Source Code

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

public class Main {
    private static final int SECOND = 1000;
    private static final int MINUTE = 60 * SECOND;
    private static final int HOUR = 60 * MINUTE;
    private static final int DAY = 24 * HOUR;

    static String humanTime(long ms) {
        StringBuffer text = new StringBuffer("");
        if (ms > DAY) {
            text.append(ms / DAY).append(" d ");
            ms %= DAY;/* w  w  w. ja  va  2s.co  m*/
        }
        if (ms > HOUR) {
            text.append(ms / HOUR).append(" h ");
            ms %= HOUR;
        }
        if (ms > MINUTE) {
            text.append(ms / MINUTE).append(" m ");
            ms %= MINUTE;
        }
        if (ms > SECOND) {
            long s = ms / SECOND;
            if (s < 10) {
                text.append('0');
            }
            text.append(s).append(" s ");
            //            ms %= SECOND;
        }
        //        text.append(ms + " ms");

        return text.toString();
    }
}

Related

  1. getMaxTimeByStringDate(String date)
  2. humanTime(long seconds)
  3. humanTime(long start, long end)
  4. toHumanable(long time_millsecod)
  5. toTime(int duration)