A class that defines a duration of time. Duration instances are immutable,
and are therefore replaced rather than modified, similar to java..
Durations can be created using the constructor, or one of the static construction
methods such as seconds or minutes.
| Modifier and Type | Field and Description |
|---|---|
| public static final Duration | INDEFINITE
An Infinite Duration. |
| private final double | millis
The value of this duration, in fractional milliseconds |
| public static final Duration | ONE
A Duration of 1 millisecond. |
| public static final Duration | UNKNOWN
A Duration of some unknown amount of time. |
| public static final Duration | ZERO
A Duration of 0 (no time). |
| Access | Constructor and Description |
|---|---|
| public | Duration(double
The number of milliseconds millis)Creates a new Duration with potentially fractional millisecond resolution. |
| Modifier and Type | Method and Description |
|---|---|
| public Duration | |
| public int | Returns: a negative integer, zero, or a positive integer as this duration is less than, equal to, or greater than the specified duration.the duration to be compared. d)Implements java. Compares durations represented by this object and the specified object. |
| public Duration | Returns: the result of dividing this duration with n. This is the same as millis / n using double arithmeticthe amount to divide by in fractional milliseconds n)Divide this instance by a number to return a new Duration instance. |
| public Duration | Returns: the result of dividing this duration by the other duration. This is the same as millis / other.millis using double arithmeticmust not be null other)
Deprecated
This method produces surprising results by not taking units into
account. Use
divide(double) instead.
Divide this instance by another Duration to return the ratio. |
| public boolean | Returns: true if this object is equal to the obj argument; false otherwise.the reference object with which to compare. obj)Overrides java. Indicates whether some other object is "equal to" this one. |
| public boolean | Returns: true if millis > other.millis using double arithmeticcannot be null other)Returns true if the specified duration is greater than (>) this instance. |
| public boolean | Returns: true if millis >= other.millis using double arithmeticcannot be null other)Returns true if the specified duration is greater than or equal to (>=) this instance. |
| public int | Returns: a hash code for thisDuration object.Overrides java. Returns a hash code for this |
| public static Duration | Returns: a Duration instance representing the specified number of hoursthe number of hours h)Factory method that returns a Duration instance representing the specified number of hours. |
| public boolean | Returns: true if this Duration is equivalent to Duration.INDEFINITE or Double.POSITIVE_INFINITY.Gets whether this Duration instance is Indefinite. |
| public boolean | Returns: true if this Duration is equivalent to Duration.UNKNOWN or Double.isNaN(millis)Gets whether this Duration instance is Unknown. |
| public boolean | |
| public boolean | Returns: true if millis <= other.millis using double arithmeticcannot be null other)Returns true if the specified duration is less than or equal to (<=) this instance. |
| public static Duration | Returns: a Duration instance of the specified number of millisecondsthe number of milliseconds ms)Factory method that returns a Duration instance for a specified number of milliseconds. |
| public static Duration | Returns: a Duration instance of the specified number of minutesthe number of minutes m)Factory method that returns a Duration instance representing the specified number of minutes. |
| public Duration | Returns: the result of multiplying this duration with the other duration. This is the same as millis * other.millis using double arithmeticmust not be null other)
Deprecated
This method produces surprising results by not taking units into
account. Use
multiply(double) instead.
Multiply this instance with a number to return a new Duration instance. |
| public Duration | Returns: the result of multiplying this duration with n. This is the same as millis * n using double arithmeticthe amount to multiply by in fractional milliseconds n)Multiply this instance with a number representing millis and return a new Duration. |
| public Duration | Returns: the result of negating this duration. This is the same as -millis using double arithmeticReturn a new Duration instance which has a negative number of milliseconds from this instance. |
| public static Duration | Returns: a Duration instance of the specified number of secondsthe number of seconds s)Factory method that returns a Duration instance representing the specified number of seconds. |
| public Duration | |
| public double | Returns: the Duration in fractional hoursReturns the number of hours in this period or Double.POSITIVE_INFINITY if the period is INDEFINITE or NaN if the period is UNKNOWN. |
| public double | Returns: the Duration in fractional millisecondsReturns the number of milliseconds in this period or Double.POSITIVE_INFINITY if the period is INDEFINITE or NaN if the period is UNKNOWN. |
| public double | Returns: the Duration in fractional minutesReturns the number of minutes in this period or Double.POSITIVE_INFINITY if the period is INDEFINITE or NaN if the period is UNKNOWN. |
| public double | Returns: the Duration in fractional secondsReturns the number of seconds in this period or Double.POSITIVE_INFINITY if the period is INDEFINITE or NaN if the period is UNKNOWN. |
| public String | Returns: a string representation of thisDuration object.Overrides java. Returns a string representation of this |
| public static Duration |
| INDEFINITE | back to summary |
|---|---|
| public static final Duration INDEFINITE An Infinite Duration. | |
| millis | back to summary |
|---|---|
| private final double millis The value of this duration, in fractional milliseconds | |
| ONE | back to summary |
|---|---|
| public static final Duration ONE A Duration of 1 millisecond. | |
| UNKNOWN | back to summary |
|---|---|
| public static final Duration UNKNOWN A Duration of some unknown amount of time. | |
| ZERO | back to summary |
|---|---|
| public static final Duration ZERO A Duration of 0 (no time). | |
| Duration | back to summary |
|---|---|
| public Duration(double millis) Creates a new Duration with potentially fractional millisecond resolution.
| |
| add | back to summary |
|---|---|
| public Duration add(Duration other) Add this instance and another Duration instance to return a new Duration instance. If either instance is INDEFINITE, return INDEFINITE. If either instance is UNKNOWN, return UNKNOWN. This method does not change the value of the called Duration instance. | |
| compareTo | back to summary |
|---|---|
| public int compareTo(Duration d) Implements java. Compares durations represented by this object and the specified object. Returns a negative integer, zero, or a positive integer as this duration is less than, equal to, or greater than the specified duration. | |
| divide | back to summary |
|---|---|
| public Duration divide(double n) Divide this instance by a number to return a new Duration instance. If the called Duration instance is INDEFINITE, return INDEFINITE. If the called Duration instance is UNKNOWN, return UNKNOWN. This method does not change the value of the called Duration instance.
| |
| divide | back to summary |
|---|---|
| public Duration divide(Duration other)
Deprecated This method produces surprising results by not taking units into
account. Use Divide this instance by another Duration to return the ratio. If both instances are INDEFINITE, return NaN. If this instance is INDEFINITE, return POSITIVE_INFINITY If the other instance is INDEFINITE, return 0.0. This function does not change the value of the called Duration instance. | |
| equals | back to summary |
|---|---|
| public boolean equals(Object obj) Overrides java. Indicates whether some other object is "equal to" this one. | |
| greaterThan | back to summary |
|---|---|
| public boolean greaterThan(Duration other) Returns true if the specified duration is greater than (>) this instance. INDEFINITE is treated as if it were positive infinity.
| |
| greaterThanOrEqualTo | back to summary |
|---|---|
| public boolean greaterThanOrEqualTo(Duration other) Returns true if the specified duration is greater than or equal to (>=) this instance. INDEFINITE is treated as if it were positive infinity.
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Returns a hash code for this
| |
| hours | back to summary |
|---|---|
| public static Duration hours(double h) Factory method that returns a Duration instance representing the specified number of hours.
| |
| isIndefinite | back to summary |
|---|---|
| public boolean isIndefinite() Gets whether this Duration instance is Indefinite. A Duration is Indefinite if it equals Duration.INDEFINITE.
| |
| isUnknown | back to summary |
|---|---|
| public boolean isUnknown() Gets whether this Duration instance is Unknown. A Duration is Unknown if it equals Duration.UNKNOWN.
| |
| lessThan | back to summary |
|---|---|
| public boolean lessThan(Duration other) Returns true if the specified duration is less than (<) this instance. INDEFINITE is treated as if it were positive infinity.
| |
| lessThanOrEqualTo | back to summary |
|---|---|
| public boolean lessThanOrEqualTo(Duration other) Returns true if the specified duration is less than or equal to (<=) this instance. INDEFINITE is treated as if it were positive infinity.
| |
| millis | back to summary |
|---|---|
| public static Duration millis(double ms) Factory method that returns a Duration instance for a specified number of milliseconds.
| |
| minutes | back to summary |
|---|---|
| public static Duration minutes(double m) Factory method that returns a Duration instance representing the specified number of minutes.
| |
| multiply | back to summary |
|---|---|
| public Duration multiply(Duration other)
Deprecated This method produces surprising results by not taking units into
account. Use Multiply this instance with a number to return a new Duration instance. If either instance is INDEFINITE, return INDEFINITE. If either Duration instance is UNKNOWN, return UNKNOWN. This method does not change the value of the called Duration instance. | |
| multiply | back to summary |
|---|---|
| public Duration multiply(double n) Multiply this instance with a number representing millis and return a new Duration. If the called Duration instance is INDEFINITE, return INDEFINITE. If the called Duration instance is UNKNOWN, return UNKNOWN. This method does not change the value of the called Duration instance.
| |
| negate | back to summary |
|---|---|
| public Duration negate() Return a new Duration instance which has a negative number of milliseconds
from this instance. For example,
| |
| seconds | back to summary |
|---|---|
| public static Duration seconds(double s) Factory method that returns a Duration instance representing the specified number of seconds.
| |
| subtract | back to summary |
|---|---|
| public Duration subtract(Duration other) Subtract other Duration instance from this instance to return a new Duration instance. If either instance is UNKNOWN, return UNKNOWN. Otherwise, if either instance is INDEFINITE, return INDEFINITE. This method does not change the value of the called Duration instance. | |
| toHours | back to summary |
|---|---|
| public double toHours() Returns the number of hours in this period or Double.POSITIVE_INFINITY if the period is INDEFINITE or NaN if the period is UNKNOWN.
| |
| toMillis | back to summary |
|---|---|
| public double toMillis() Returns the number of milliseconds in this period or Double.POSITIVE_INFINITY if the period is INDEFINITE or NaN if the period is UNKNOWN.
| |
| toMinutes | back to summary |
|---|---|
| public double toMinutes() Returns the number of minutes in this period or Double.POSITIVE_INFINITY if the period is INDEFINITE or NaN if the period is UNKNOWN.
| |
| toSeconds | back to summary |
|---|---|
| public double toSeconds() Returns the number of seconds in this period or Double.POSITIVE_INFINITY if the period is INDEFINITE or NaN if the period is UNKNOWN.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Returns a string representation of this | |
| valueOf | back to summary |
|---|---|
| public static Duration valueOf(String time) Factory method that returns a Duration instance for a specified amount of time. The syntax is "[number][ms|s|m|h]". | |