List of utility methods to do Duration Format
String | formatDuration(Duration duration) format Duration long hours = Math.abs(duration.toHours()); long minutes = Math.abs(duration.minus(duration.toHours(), ChronoUnit.HOURS).toMinutes()); long seconds = Math.abs(duration.minus(duration.toMinutes(), ChronoUnit.MINUTES).getSeconds()); final String f = String.format("%02d:%02d:%02d", hours, minutes, seconds); return f; |
String | formatDuration(Duration duration) format Duration long seconds = duration.getSeconds(); long absSeconds = Math.abs(seconds); String positive = String.format("%d h %d m %d s", absSeconds / 3600, (absSeconds % 3600) / 60, absSeconds % 60); return seconds < 0 ? "-" + positive : positive; |
String | formatDuration(Duration duration, boolean inProgress) format Duration int hours = (int) duration.toHours(); int minutes = (int) duration.toMinutes() - (hours * 60); int seconds = (int) (duration.getSeconds() % 60); if (seconds >= 30) { minutes++; if (minutes >= 60) { hours++; ... |
String | formatDuration(final Duration duration) format Duration long absSeconds = Math.abs(duration.getSeconds()); long seconds = absSeconds % 60; long minutes = (absSeconds % 3600) / 60; long hours = absSeconds / 3600; return (hours == 0 ? "" : hours + ":") + (minutes == 0 ? "00" : minutes < 10 ? String.valueOf("0" + minutes) : String.valueOf(minutes)) + ":" + (seconds == 0 ? "00" : seconds < 10 ? String.valueOf("0" + seconds) : String.valueOf(seconds)); ... |
String | formatDuration(final Duration duration, final boolean wrapInDurationFunction) format Duration if (duration.getSeconds() == 0 && duration.getNano() == 0) { if (wrapInDurationFunction) { return "duration( \"PT0S\" )"; } else { return "PT0S"; final long days = duration.getSeconds() / SECONDS_IN_A_DAY; ... |
String | formatDuration(final int duration) Formats the specified number of seconds as a string containing the number of days, hours, minutes and seconds. final StringBuilder buff = new StringBuilder(); int seconds = duration; seconds -= doDuration(buff, seconds, 60 * 60 * 24, "day"); seconds -= doDuration(buff, seconds, 60 * 60, "hour"); seconds -= doDuration(buff, seconds, 60, "minute"); seconds -= doDuration(buff, seconds, 1, "second"); return buff.length() == 0 ? "0 seconds" : buff.toString(); |
String | formatDuration(final long milliSeconds) format Duration final long duration = milliSeconds / 60000; final long durationHours = duration / 60; final long durationMinutes = (duration % 60); final StringBuffer buf = new StringBuffer(10); buf.append(durationHours); if (durationMinutes < 10) buf.append(":0"); else ... |
String | formatDuration(final long seconds) format Duration return String.format("%d:%02d:%02d", seconds / 3600, (seconds % 3600) / 60, (seconds % 60)); |
String | formatDuration(int durationMins) format Duration int minutes = durationMins % 60; int hours = (durationMins - minutes) / 60; return hours + ":" + String.valueOf(minutes % 60 + 100).substring(1, 3); |
String | formatDuration(int seconds) format Duration if (seconds == 0) { return ""; int days = seconds / 86400; int hours = (seconds % 86400) / 3600; int mins = (seconds % 3600) / 60; int secs = seconds % 60; StringBuffer buf = new StringBuffer(); ... |