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]s
59:59[.9][min]
23h
(hours)23:59h
23h 59min
23:59:59[.9]
(hours, minutes and seconds)23h 59min 59[.9]sec
7d
(days)7d 23h
7d 23:59
7d 23h 59min
7d 23:59:59[.9]
7d 23h 59min 59[.9]s
1w
(weeks, i.e. intervals of seven days)1w 1d
1w 1d 23h
1w 1d 23:59
1w 1d 23h 59min
1w 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.