Java Utililty Methods Duration Create

List of utility methods to do Duration Create

Description

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

Method

DurationgetDuration(final Date started, final Date finished)
Get the duration between when something was started and finished.
if (started == null || started.getTime() == 0) {
    return Duration.ZERO;
} else if (finished == null || finished.getTime() == 0) {
    return Duration.ofMillis(new Date().getTime() - started.getTime());
} else {
    return Duration.ofMillis(finished.getTime() - started.getTime());
DurationgetDuration(Object o, TemporalUnit unit)
get Duration
if (o != null && o instanceof Duration) {
    return (Duration) o;
try {
    return Duration.of(getLong(o), unit);
} catch (IllegalArgumentException e) {
    throw new IllegalArgumentException("Don't know how to convert " + o + " to Duration", e);