Java Millisecond Convert millisToString(long ms)

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

Description

millis To String

License

Open Source License

Declaration

public static String millisToString(long ms) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static String millisToString(long ms) {
        int days = (int) (ms / (1000 * 60 * 60 * 24)) % 7;
        int hours = (int) (ms / (1000 * 60 * 60)) % 24;
        int mins = (int) (ms / (1000 * 60)) % 60;
        int secs = (int) (ms / 1000) % 60;
        if (days > 0) {
            return String.format("%s days, %sh %sm %ss", days, hours, mins, secs);
        } else if (hours > 0) {
            return String.format("%sh %sm %ss", hours, mins, secs);
        } else {//from   w  ww.  jav a  2 s.  c o  m
            return String.format("%sm %ss", mins, secs);
        }
    }
}

Related

  1. millisToSeconds(long millis)
  2. millisToSeconds(long millis)
  3. millisToShortDHMS(long duration)
  4. millisToString(float millis)
  5. millisToString(long millis)
  6. millisToString(long t)
  7. millisToStringDouble(double millis)
  8. millisToText(long millis)
  9. millisToTime(final long time)