List of utility methods to do TimeUnit Format
String | format(final long duration, final TimeUnit sourceUnit, final TimeUnit min) format return format(duration, sourceUnit, min, max());
|
String | formatDuration(long time, TimeUnit unit) Formats a String duration property (time + optional unit). return String.valueOf(time) + ' ' + unit.name(); |
String | formatHighest(long duration, final TimeUnit max) Converts time to a human readable format within the specified range final TimeUnit[] units = TimeUnit.values(); final StringBuilder res = new StringBuilder(); TimeUnit current = max; while (duration > 0) { final long temp = current.convert(duration, TimeUnit.MILLISECONDS); if (temp > 0) { duration -= current.toMillis(temp); res.append(temp).append(" ").append(current.name().toLowerCase()); ... |
String | formatMillis(long duration, TimeUnit max, TimeUnit min, boolean useAbbreviation) Converts time to a human readable format within the specified range http://stackoverflow.com/questions/3859288/how-to-calculate-time-ago-in-java StringBuilder res = new StringBuilder(); TimeUnit current = max; while (duration > 0) { long temp = current.convert(duration, MILLISECONDS); if (temp > 0) { duration -= current.toMillis(temp); res.append(temp).append(" ").append(current.name().toLowerCase()); if (temp < 2) { ... |
String | formatMinutesSeconds(final long sourceDuration, final TimeUnit sourceUnit) Formats the specified duration in 'mm:ss.SSS' format. final long millis = TimeUnit.MILLISECONDS.convert(sourceDuration, sourceUnit); final long millisInMinute = TimeUnit.MILLISECONDS.convert(1, TimeUnit.MINUTES); final int minutes = (int) (millis / millisInMinute); final long secondsMillisLeft = millis - minutes * millisInMinute; final long millisInSecond = TimeUnit.MILLISECONDS.convert(1, TimeUnit.SECONDS); final int seconds = (int) (secondsMillisLeft / millisInSecond); final long millisLeft = secondsMillisLeft - seconds * millisInSecond; return pad2Places(minutes) + ":" + pad2Places(seconds) + "." + pad3Places(millisLeft); ... |
String | formatTime(long dt, TimeUnit input, TimeUnit output, int decimalPlaces) Returns a formatted time difference string if (input == null) throw new NullPointerException("unit"); if (output == null) throw new NullPointerException("output"); double inputMult; double outputMult; String strOutUnit; switch (input) { ... |