public final class Duration
extends java.lang.Object
| Constructor and Description |
|---|
Duration(double seconds) |
Duration(long ms) |
Duration(java.lang.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(java.lang.Object obj) |
int |
hashCode() |
boolean |
isZero() |
long |
milliseconds() |
Duration |
multiply(double factor) |
double |
toSeconds() |
java.lang.String |
toString() |
public Duration(long ms)
public Duration(double seconds)
public Duration(java.lang.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 java.lang.String toString()
toString in class java.lang.Objectpublic Duration add(Duration other)
this and otherpublic Duration multiply(double factor)
factor as long as this durationpublic Duration divide(double divisor)
divisorth of this duration longpublic boolean isZero()
public int hashCode()
hashCode in class java.lang.Objectpublic boolean equals(@Nullable java.lang.Object obj)
equals in class java.lang.Object