@Test public void testValues() { int i; long[] values = { 0, 100, 1000, 1500, 64000, 124531, 3651782, 86400000, 86434349, 1075634299, 86480001, 86400001 }; String[] expected = { "0 ms", "100 ms", "1.0 seconds", "1.500 seconds", "0:01:04", "0:02:04", "1:00:51", "1 day", "1 day", "12 days 10:47:14", "1 day 00:01:20", "1 day" }; for (i = 0; i < values.length; i++) { assertEquals(expected[i], StringUtils.getReadableTime(values[i])); } }
public static String getReadableTime(long time_ms) { StringBuilder output = new StringBuilder(); long time_delta = time_ms; int milliseconds = (int) (time_delta % 1000); time_delta /= 1000; int seconds = (int) (time_delta % 60); time_delta /= 60; int minutes = (int) (time_delta % 60); time_delta /= 60; int hours = (int) (time_delta % 24); int days = (int) (time_delta / 24); if (days != 0) { output.append(days); output.append(" day"); if (days > 1) { output.append("s"); } } if ((hours != 0) || (minutes != 0)) { if (output.length() > 0) { output.append(String.format(" %02d:%02d:%02d", hours, minutes, seconds)); } else { output.append(String.format("%d:%02d:%02d", hours, minutes, seconds)); } } else if (output.length() > 0) { return output.toString(); } else if (seconds != 0) { output.append(String.format("%d.%d seconds", seconds, milliseconds)); } else if (milliseconds != 0) { output.append(String.format("%d ms", milliseconds)); } return (output.length() == 0 ? "0 ms" : output.toString()); }
StringUtils { public static String getReadableTime(long time_ms) { StringBuilder output = new StringBuilder(); long time_delta = time_ms; int milliseconds = (int) (time_delta % 1000); time_delta /= 1000; int seconds = (int) (time_delta % 60); time_delta /= 60; int minutes = (int) (time_delta % 60); time_delta /= 60; int hours = (int) (time_delta % 24); int days = (int) (time_delta / 24); if (days != 0) { output.append(days); output.append(" day"); if (days > 1) { output.append("s"); } } if ((hours != 0) || (minutes != 0)) { if (output.length() > 0) { output.append(String.format(" %02d:%02d:%02d", hours, minutes, seconds)); } else { output.append(String.format("%d:%02d:%02d", hours, minutes, seconds)); } } else if (output.length() > 0) { return output.toString(); } else if (seconds != 0) { output.append(String.format("%d.%d seconds", seconds, milliseconds)); } else if (milliseconds != 0) { output.append(String.format("%d ms", milliseconds)); } return (output.length() == 0 ? "0 ms" : output.toString()); } }
StringUtils { public static String getReadableTime(long time_ms) { StringBuilder output = new StringBuilder(); long time_delta = time_ms; int milliseconds = (int) (time_delta % 1000); time_delta /= 1000; int seconds = (int) (time_delta % 60); time_delta /= 60; int minutes = (int) (time_delta % 60); time_delta /= 60; int hours = (int) (time_delta % 24); int days = (int) (time_delta / 24); if (days != 0) { output.append(days); output.append(" day"); if (days > 1) { output.append("s"); } } if ((hours != 0) || (minutes != 0)) { if (output.length() > 0) { output.append(String.format(" %02d:%02d:%02d", hours, minutes, seconds)); } else { output.append(String.format("%d:%02d:%02d", hours, minutes, seconds)); } } else if (output.length() > 0) { return output.toString(); } else if (seconds != 0) { output.append(String.format("%d.%d seconds", seconds, milliseconds)); } else if (milliseconds != 0) { output.append(String.format("%d ms", milliseconds)); } return (output.length() == 0 ? "0 ms" : output.toString()); } private  StringUtils(); }
StringUtils { public static String getReadableTime(long time_ms) { StringBuilder output = new StringBuilder(); long time_delta = time_ms; int milliseconds = (int) (time_delta % 1000); time_delta /= 1000; int seconds = (int) (time_delta % 60); time_delta /= 60; int minutes = (int) (time_delta % 60); time_delta /= 60; int hours = (int) (time_delta % 24); int days = (int) (time_delta / 24); if (days != 0) { output.append(days); output.append(" day"); if (days > 1) { output.append("s"); } } if ((hours != 0) || (minutes != 0)) { if (output.length() > 0) { output.append(String.format(" %02d:%02d:%02d", hours, minutes, seconds)); } else { output.append(String.format("%d:%02d:%02d", hours, minutes, seconds)); } } else if (output.length() > 0) { return output.toString(); } else if (seconds != 0) { output.append(String.format("%d.%d seconds", seconds, milliseconds)); } else if (milliseconds != 0) { output.append(String.format("%d ms", milliseconds)); } return (output.length() == 0 ? "0 ms" : output.toString()); } private  StringUtils(); static boolean isOnlyWhitespace(String str); static boolean isPossiblyJavaClass(String s); static String getReadableTime(long time_ms); static int nthIndexOf(String str, String substr, int n); static boolean startsWithFnameChars(String value); static boolean startsWithURIChars(String value); static int countURIEndingPushback(String value); static boolean isAlphanumeric(String str); static int patindexOf(String value, Pattern pattern); static boolean startsWithFpathChar(String value); static int countPushback(String capture, Pattern pat); static int whitespaceOrControlLength(String str, int off, boolean shouldMatch); }
StringUtils { public static String getReadableTime(long time_ms) { StringBuilder output = new StringBuilder(); long time_delta = time_ms; int milliseconds = (int) (time_delta % 1000); time_delta /= 1000; int seconds = (int) (time_delta % 60); time_delta /= 60; int minutes = (int) (time_delta % 60); time_delta /= 60; int hours = (int) (time_delta % 24); int days = (int) (time_delta / 24); if (days != 0) { output.append(days); output.append(" day"); if (days > 1) { output.append("s"); } } if ((hours != 0) || (minutes != 0)) { if (output.length() > 0) { output.append(String.format(" %02d:%02d:%02d", hours, minutes, seconds)); } else { output.append(String.format("%d:%02d:%02d", hours, minutes, seconds)); } } else if (output.length() > 0) { return output.toString(); } else if (seconds != 0) { output.append(String.format("%d.%d seconds", seconds, milliseconds)); } else if (milliseconds != 0) { output.append(String.format("%d ms", milliseconds)); } return (output.length() == 0 ? "0 ms" : output.toString()); } private  StringUtils(); static boolean isOnlyWhitespace(String str); static boolean isPossiblyJavaClass(String s); static String getReadableTime(long time_ms); static int nthIndexOf(String str, String substr, int n); static boolean startsWithFnameChars(String value); static boolean startsWithURIChars(String value); static int countURIEndingPushback(String value); static boolean isAlphanumeric(String str); static int patindexOf(String value, Pattern pattern); static boolean startsWithFpathChar(String value); static int countPushback(String capture, Pattern pat); static int whitespaceOrControlLength(String str, int off, boolean shouldMatch); static final Pattern STANDARD_EOL; static final Pattern APOS_NO_BSESC; static final Pattern END_C_COMMENT; }