Here you can find the source of formatDuration(long ms)
public static String formatDuration(long ms)
//package com.java2s; // it under the terms of the GNU General Public License as published by public class Main { public static String formatDuration(long ms) { double nbSec = (double) ms / 1000.0; return formatDuration(nbSec); }/*w ww .ja v a 2s .c o m*/ public static String formatDuration(double nbSeconds) { if (nbSeconds < 10.0) { String str = "" + nbSeconds; int idx = str.indexOf('.'); if (idx > 0) if (str.length() > idx + 3) str = str.substring(0, idx + 3); return str + " sec."; } else { int intDuration = (int) nbSeconds; if (nbSeconds < 60.0) return "" + intDuration + " sec."; else if (intDuration < 3600) { int mn = intDuration / 60; int sec = intDuration - 60 * mn; return "" + mn + " mn " + ((sec < 10) ? "0" : "") + sec + " sec."; } else if (intDuration < 24 * 3600) { int h = intDuration / 3600; intDuration -= h * 3600; int mn = intDuration / 60; int sec = intDuration - 60 * mn; return "" + h + " h " + ((mn < 10) ? "0" : "") + mn + " mn " + ((sec < 10) ? "0" : "") + sec + " sec."; } else { int days = intDuration / (24 * 3600); return "" + days + " day" + ((days > 1) ? "s " : " ") + formatDuration((double) intDuration - (days * 24 * 3600)); } } } }