Here you can find the source of millisToString(long ms)
public static String millisToString(long ms)
//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); } } }