org.goda.time
public final class Duration extends BaseDuration implements ReadableDuration, Serializable
A duration is defined by a fixed number of milliseconds.
There is no concept of fields, such as days or seconds, as these fields can vary in length.
A duration may be converted to a Period to obtain field values.
This conversion will typically cause a loss of precision however.
Duration is thread-safe and immutable.
| Modifier and Type | Field and Description |
|---|---|
static Duration |
ZERO
Constant representing zero millisecond duration
|
| Constructor and Description |
|---|
Duration(long duration)
Creates a duration from the given millisecond duration.
|
Duration(long startInstant,
long endInstant)
Creates a duration from the given interval endpoints.
|
Duration(Object duration)
Creates a duration from the specified object using the
ConverterManager. |
Duration(ReadableInstant start,
ReadableInstant end)
Creates a duration from the given interval endpoints.
|
| Modifier and Type | Method and Description |
|---|---|
Duration |
minus(long amount)
Returns a new duration with this length minus that specified.
|
Duration |
minus(ReadableDuration amount)
Returns a new duration with this length minus that specified.
|
Duration |
plus(long amount)
Returns a new duration with this length plus that specified.
|
Duration |
plus(ReadableDuration amount)
Returns a new duration with this length plus that specified.
|
Duration |
toDuration()
Get this duration as an immutable
Duration object
by returning this. |
Duration |
withDurationAdded(long durationToAdd,
int scalar)
Returns a new duration with this length plus that specified multiplied by the scalar.
|
Duration |
withDurationAdded(ReadableDuration durationToAdd,
int scalar)
Returns a new duration with this length plus that specified multiplied by the scalar.
|
Duration |
withMillis(long duration)
Creates a new Duration instance with a different milisecond length.
|
getMillis, setMillis, toIntervalFrom, toIntervalTo, toPeriod, toPeriod, toPeriod, toPeriodFrom, toPeriodFrom, toPeriodTo, toPeriodTocompareTo, equals, hashCode, isEqual, isLongerThan, isShorterThan, toPeriod, toStringclone, finalize, getClass, notify, notifyAll, wait, wait, waitcompareTo, equals, getMillis, hashCode, isEqual, isLongerThan, isShorterThan, toPeriod, toStringpublic static final Duration ZERO
public Duration(long duration)
duration - the duration, in millisecondspublic Duration(long startInstant,
long endInstant)
startInstant - interval start, in millisecondsendInstant - interval end, in millisecondsArithmeticException - if the duration exceeds a 64 bit longpublic Duration(ReadableInstant start, ReadableInstant end)
start - interval start, null means nowend - interval end, null means nowArithmeticException - if the duration exceeds a 64 bit longpublic Duration(Object duration)
ConverterManager.duration - duration to convertIllegalArgumentException - if duration is invalidpublic Duration toDuration()
Duration object
by returning this.toDuration in interface ReadableDurationtoDuration in class AbstractDurationthispublic Duration withMillis(long duration)
duration - the new length of the durationpublic Duration withDurationAdded(long durationToAdd, int scalar)
If the addition is zero, this instance is returned.
durationToAdd - the duration to add to this onescalar - the amount of times to add, such as -1 to subtract oncepublic Duration withDurationAdded(ReadableDuration durationToAdd, int scalar)
If the addition is zero, this instance is returned.
durationToAdd - the duration to add to this one, null means zeroscalar - the amount of times to add, such as -1 to subtract oncepublic Duration plus(long amount)
If the addition is zero, this instance is returned.
amount - the duration to add to this onepublic Duration plus(ReadableDuration amount)
If the amount is zero, this instance is returned.
amount - the duration to add to this one, null means zeropublic Duration minus(long amount)
If the addition is zero, this instance is returned.
amount - the duration to take away from this onepublic Duration minus(ReadableDuration amount)
If the amount is zero, this instance is returned.
amount - the duration to take away from this one, null means zeroCopyright © 2013 os-cillation GmbH. All rights reserved.