List of utility methods to do Duration to
float | durationToFloat(Duration duration) duration To Float Float hours = Float.valueOf(duration.toMinutes()) / 60;
return round(hours, 2);
|
String | durationToString(Duration d) duration To String String s = ""; boolean started = false; if (d.toDays() >= 365) { started = true; s += d.toDays() / 365 + " year" + ((d.toDays() / 365 != 1) ? "s" : "") + ", "; d = d.minus(Duration.ofDays(d.toDays() / 365 * 365)); if (started || d.toDays() >= 30) { ... |
String | toDuration(Long unixTime) to Duration LocalDateTime start = LocalDateTime.ofInstant(Instant.ofEpochSecond(unixTime), ZoneId.systemDefault()); LocalDateTime end = LocalDateTime.ofInstant(Instant.ofEpochSecond(0), ZoneId.systemDefault()); Duration duration = Duration.between(end, start); long hours = duration.toHours(); long minutes = duration.minusHours(hours).toMinutes(); return String.format("%02d:%02d", hours, minutes); |
Duration | toDuration(String durationString) to Duration Duration dur = Duration.ZERO; Matcher match = DUR_PAT.matcher(durationString); while (match.find()) { long amount = Long.parseLong(match.group(1)); switch (match.group(2)) { case "d": dur = dur.plusDays(amount); break; ... |
BigInteger | toMicro(Duration duration) to Micro BigInteger ret = BigInteger.valueOf(duration.getSeconds());
ret = ret.multiply(micromult);
ret = ret.add(BigInteger.valueOf(duration.getNano() / 1000));
return ret;
|
double | toSeconds(final Duration time) to Seconds double result = time.getSeconds(); result += ((double) time.getNano()) / NANOS_PER_SECOND; return result; |
long | toTicks(Duration duration) to Ticks return duration.toMillis() / 50;
|
long | toUnit(TemporalUnit unit, Duration duration) to Unit switch ((ChronoUnit) unit) { case NANOS: return duration.toNanos(); case MICROS: return toMicros(duration); case MILLIS: return duration.toMillis(); case SECONDS: ... |