public final class Duration extends Object
| Constructor and Description |
|---|
Duration(double seconds) |
Duration(long ms) |
Duration(String s)
Creates a
Duration from a string representation. |
| Modifier and Type | Method and Description |
|---|---|
Duration |
add(Duration other) |
Duration |
divide(double divisor) |
boolean |
equals(Object obj) |
int |
hashCode() |
boolean |
isZero() |
long |
milliseconds() |
Duration |
multiply(double factor) |
double |
toSeconds() |
String |
toString() |
public Duration(long ms)
public Duration(double seconds)
public Duration(String s)
Duration from a string representation.
Accepts duration specifications in any of the following formats:
999ms (milliseconds)59[.9]s (seconds)59min (minutes)59min 59[.9]s59:59[.9][min]23h (hours)23:59h23h 59min23:59:59[.9] (hours, minutes and seconds)23h 59min 59[.9]sec7d (days)7d 23h7d 23:597d 23h 59min7d 23:59:59[.9]7d 23h 59min 59[.9]s1w (weeks, i.e. intervals of seven days)1w 1d1w 1d 23h1w 1d 23:591w 1d 23h 59min1w 1d 23:59:59[.9]1w 1d 23h 59min 59[.9]s
Notice that the pattern "12:34" is intentionally not valid, because it is ambiguous
("hh:mm" vs. "mm:ss"). Same for "99[.9]".
Some alternative unit notations are allowed:
public long milliseconds()
public double toSeconds()
public Duration add(Duration other)
this and otherpublic Duration multiply(double factor)
public Duration divide(double divisor)
public boolean isZero()
Copyright © 2018 Arno Unkrig. All rights reserved.