APIdia Launch Partner
Top Description Fields Constructors Methods
javafx.util

public Class Duration

extends Object
implements Comparable<Duration>, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.lang.Comparable
Imports
java.io.Serializable, javafx.beans.NamedArg

A class that defines a duration of time. Duration instances are immutable, and are therefore replaced rather than modified, similar to java.math.BigDecimal. Durations can be created using the constructor, or one of the static construction methods such as seconds or minutes.

Since
JavaFX 2.0

Field Summary

Modifier and TypeField 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).

Constructor Summary

AccessConstructor and Description
public
Duration(double
The number of milliseconds
millis
)

Creates a new Duration with potentially fractional millisecond resolution.

Method Summary

Modifier and TypeMethod and Description
public Duration

Returns:

the result of adding this duration to the other duration. This is the same as millis + other.millis using double arithmetic
add
(Duration
must not be null
other
)

Add this instance and another Duration instance to return a new Duration instance.

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.
compareTo
(Duration
the duration to be compared.
d
)

Implements java.lang.Comparable.compareTo.

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 arithmetic
divide
(double
the 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 arithmetic
divide
(Duration
must 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.
equals
(Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public boolean

Returns:

true if millis > other.millis using double arithmetic
greaterThan
(Duration
cannot be null
other
)

Returns true if the specified duration is greater than (>) this instance.

public boolean

Returns:

true if millis >= other.millis using double arithmetic
greaterThanOrEqualTo
(Duration
cannot be null
other
)

Returns true if the specified duration is greater than or equal to (>=) this instance.

public int

Returns:

a hash code for this Duration object.
hashCode
()

Overrides java.lang.Object.hashCode.

Returns a hash code for this Duration object.

public static Duration

Returns:

a Duration instance representing the specified number of hours
hours
(double
the 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.
isIndefinite
()

Gets whether this Duration instance is Indefinite.

public boolean

Returns:

true if this Duration is equivalent to Duration.UNKNOWN or Double.isNaN(millis)
isUnknown
()

Gets whether this Duration instance is Unknown.

public boolean

Returns:

true if millis < other.millis using double arithmetic
lessThan
(Duration
cannot be null
other
)

Returns true if the specified duration is less than (<) this instance.

public boolean

Returns:

true if millis <= other.millis using double arithmetic
lessThanOrEqualTo
(Duration
cannot 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 milliseconds
millis
(double
the 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 minutes
minutes
(double
the 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 arithmetic
multiply
(Duration
must 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 arithmetic
multiply
(double
the 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 arithmetic
negate
()

Return 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 seconds
seconds
(double
the number of seconds
s
)

Factory method that returns a Duration instance representing the specified number of seconds.

public Duration

Returns:

the result of subtracting the other duration from this duration. This is the same as millis - other.millis using double arithmetic
subtract
(Duration
must not be null
other
)

Subtract other Duration instance from this instance to return a new Duration instance.

public double

Returns:

the Duration in fractional hours
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.

public double

Returns:

the Duration in fractional milliseconds
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.

public double

Returns:

the Duration in fractional minutes
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.

public double

Returns:

the Duration in fractional seconds
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.

public String

Returns:

a string representation of this Duration object.
toString
()

Overrides java.lang.Object.toString.

Returns a string representation of this Duration object.

public static Duration

Returns:

a Duration which is represented by the time
valueOf
(String
A non-null string properly formatted. Leading or trailing spaces will not parse correctly. Throws a NullPointerException if time is null.
time
)

Factory method that returns a Duration instance for a specified amount of time.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

INDEFINITEback to summary
public static final Duration INDEFINITE

An Infinite Duration.

millisback to summary
private final double millis

The value of this duration, in fractional milliseconds

ONEback to summary
public static final Duration ONE

A Duration of 1 millisecond.

UNKNOWNback to summary
public static final Duration UNKNOWN

A Duration of some unknown amount of time.

ZEROback to summary
public static final Duration ZERO

A Duration of 0 (no time).

Constructor Detail

Durationback to summary
public Duration(double millis)

Creates a new Duration with potentially fractional millisecond resolution.

Parameters
millis:double

The number of milliseconds

Method Detail

addback 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.

Parameters
other:Duration

must not be null

Returns:Duration

the result of adding this duration to the other duration. This is the same as millis + other.millis using double arithmetic

compareToback to summary
public int compareTo(Duration d)

Implements java.lang.Comparable.compareTo.

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.

Parameters
d:Duration

the duration to be compared.

Returns:int

a negative integer, zero, or a positive integer as this duration is less than, equal to, or greater than the specified duration.

Annotations
@Override
divideback 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.

Parameters
n:double

the amount to divide by in fractional milliseconds

Returns:Duration

the result of dividing this duration with n. This is the same as millis / n using double arithmetic

divideback to summary
public Duration divide(Duration 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. 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.

Parameters
other:Duration

must not be null

Returns:Duration

the result of dividing this duration by the other duration. This is the same as millis / other.millis using double arithmetic

Annotations
@Deprecated
equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

Parameters
obj:Object

the reference object with which to compare.

Returns:boolean

true if this object is equal to the obj argument; false otherwise.

Annotations
@Override
greaterThanback 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.

Parameters
other:Duration

cannot be null

Returns:boolean

true if millis > other.millis using double arithmetic

greaterThanOrEqualToback 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.

Parameters
other:Duration

cannot be null

Returns:boolean

true if millis >= other.millis using double arithmetic

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code for this Duration object.

Returns:int

a hash code for this Duration object.

Annotations
@Override
hoursback to summary
public static Duration hours(double h)

Factory method that returns a Duration instance representing the specified number of hours.

Parameters
h:double

the number of hours

Returns:Duration

a Duration instance representing the specified number of hours

isIndefiniteback to summary
public boolean isIndefinite()

Gets whether this Duration instance is Indefinite. A Duration is Indefinite if it equals Duration.INDEFINITE.

Returns:boolean

true if this Duration is equivalent to Duration.INDEFINITE or Double.POSITIVE_INFINITY.

isUnknownback to summary
public boolean isUnknown()

Gets whether this Duration instance is Unknown. A Duration is Unknown if it equals Duration.UNKNOWN.

Returns:boolean

true if this Duration is equivalent to Duration.UNKNOWN or Double.isNaN(millis)

lessThanback 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.

Parameters
other:Duration

cannot be null

Returns:boolean

true if millis < other.millis using double arithmetic

lessThanOrEqualToback 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.

Parameters
other:Duration

cannot be null

Returns:boolean

true if millis <= other.millis using double arithmetic

millisback to summary
public static Duration millis(double ms)

Factory method that returns a Duration instance for a specified number of milliseconds.

Parameters
ms:double

the number of milliseconds

Returns:Duration

a Duration instance of the specified number of milliseconds

minutesback to summary
public static Duration minutes(double m)

Factory method that returns a Duration instance representing the specified number of minutes.

Parameters
m:double

the number of minutes

Returns:Duration

a Duration instance of the specified number of minutes

multiplyback to summary
public Duration multiply(Duration 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. 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.

Parameters
other:Duration

must not be null

Returns:Duration

the result of multiplying this duration with the other duration. This is the same as millis * other.millis using double arithmetic

Annotations
@Deprecated
multiplyback 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.

Parameters
n:double

the amount to multiply by in fractional milliseconds

Returns:Duration

the result of multiplying this duration with n. This is the same as millis * n using double arithmetic

negateback to summary
public Duration negate()

Return a new Duration instance which has a negative number of milliseconds from this instance. For example, Duration.millis(50).negate() returns a Duration of -50 milliseconds. If the called Duration instance is INDEFINITE, return INDEFINITE. This function does not change the value of the called Duration instance.

Returns:Duration

the result of negating this duration. This is the same as -millis using double arithmetic

secondsback to summary
public static Duration seconds(double s)

Factory method that returns a Duration instance representing the specified number of seconds.

Parameters
s:double

the number of seconds

Returns:Duration

a Duration instance of the specified number of seconds

subtractback 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.

Parameters
other:Duration

must not be null

Returns:Duration

the result of subtracting the other duration from this duration. This is the same as millis - other.millis using double arithmetic

toHoursback 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.

Returns:double

the Duration in fractional hours

toMillisback 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.

Returns:double

the Duration in fractional milliseconds

toMinutesback 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.

Returns:double

the Duration in fractional minutes

toSecondsback 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.

Returns:double

the Duration in fractional seconds

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a string representation of this Duration object.

Returns:String

a string representation of this Duration object.

Annotations
@Override
valueOfback 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]".

Parameters
time:String

A non-null string properly formatted. Leading or trailing spaces will not parse correctly. Throws a NullPointerException if time is null.

Returns:Duration

a Duration which is represented by the time