Java Utililty Methods Duration to

List of utility methods to do Duration to

Description

The list of methods to do Duration to are organized into topic(s).

Method

floatdurationToFloat(Duration duration)
duration To Float
Float hours = Float.valueOf(duration.toMinutes()) / 60;
return round(hours, 2);
StringdurationToString(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) {
...
StringtoDuration(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);
DurationtoDuration(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;
...
BigIntegertoMicro(Duration duration)
to Micro
BigInteger ret = BigInteger.valueOf(duration.getSeconds());
ret = ret.multiply(micromult);
ret = ret.add(BigInteger.valueOf(duration.getNano() / 1000));
return ret;
doubletoSeconds(final Duration time)
to Seconds
double result = time.getSeconds();
result += ((double) time.getNano()) / NANOS_PER_SECOND;
return result;
longtoTicks(Duration duration)
to Ticks
return duration.toMillis() / 50;
longtoUnit(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:
...