public class Duration extends Object implements Comparable<Duration>, Serializable
| Modifier and Type | Field and Description |
|---|---|
static long |
DAY
A DAY = 24 hours (for a variable day, see CalendarUnit)
|
static long |
HOUR
An HOUR = 60 minutes
|
protected long |
millis
Non-leap Milliseconds since an epoch
|
static long |
MILLISECOND
A MILLISECOND = one thousandth of a second
|
static long |
MINUTE
A MINUTE = 60 seconds
|
protected int |
nanos
Nanoseconds used by high-resolution time stamps
|
static long |
SECOND
A SECOND = One second is the time that elapses during 9,192,631,770 cycles of the
radiation produced by the transition between two levels of the cesium 133 atom...
|
static long |
WEEK
A WEEK = a fixed set of seven 24-hour days
|
| Constructor and Description |
|---|
Duration()
Constructor for a duration of zero.
|
Duration(long millis)
Duration specified in milliseconds.
|
Duration(long seconds,
int nanos)
Seconds + nanos pair will always be adjusted so that nanos is positive.
|
Duration(String duration)
Constructor parsing from a string.
|
| Modifier and Type | Method and Description |
|---|---|
Duration |
add(Duration dur)
Add a duration, producing a new duration.
|
Duration |
add(long milliseconds)
Add fixed number of (+/-) milliseconds to a Duration, producing a new Duration.
|
Duration |
add(long seconds,
int nanos)
Add seconds and nanoseconds to a Duration, producing a new Duration.
|
int |
compareTo(Duration other)
Return relative comparison between two Durations.
|
boolean |
equals(Object other)
Two durations are equal if internal values are identical.
|
int |
getNanos()
Return fractional seconds in nanoseconds
Sign of value will match whole time value. |
long |
getSeconds()
Return duration truncated seconds.
|
int |
hashCode() |
static Duration |
parse(String str)
Return a duration parsed from a string.
|
long |
toMillis()
Return time truncated to milliseconds
|
String |
toString()
Output duration as a string.
|
public static final long MILLISECOND
public static final long SECOND
public static final long MINUTE
public static final long HOUR
public static final long DAY
public static final long WEEK
protected long millis
protected int nanos
public Duration()
public Duration(String duration)
duration - String representation of a duration.public Duration(long millis)
millis - public Duration(long seconds,
int nanos)
seconds - nanos - public Duration add(Duration dur)
dur - public Duration add(long milliseconds)
milliseconds - public Duration add(long seconds, int nanos)
seconds - nanos - public int compareTo(Duration other)
compareTo in interface Comparable<Duration>other - Duration to compare topublic boolean equals(Object other)
public int getNanos()
public long toMillis()
public long getSeconds()
public static Duration parse(String str)
str - of format similar to "1h15m12s" or "8 weeks, 3.5 days" or [5'13"]Copyright © 2014. All Rights Reserved.