-
- All Implemented Interfaces:
-
java.lang.Comparable
public class Duration implements Comparable<Duration>
Replacement for Java duration class which has only been introduced in SDK 26
-
-
Method Summary
Modifier and Type Method Description static DurationofNanos(long nanoSeconds)Returns a new Duration object based on amount of nanoseconds. static DurationofMillis(long milliSeconds)Returns a new Duration object based on amount of milliseconds. static DurationofMillis(double milliSeconds)Returns a new Duration object based on amount of fractional milliseconds. static DurationofSeconds(double seconds)Returns a new Duration object based on amount of fractional seconds. longtoNanos()Returns the amount of nanoseconds in this duration. inttoMillis()Returns the amount of milliseconds in this duration. doubletoMillisFractional()Returns the amount of milliseconds in this duration. doubletoSeconds()Returns the amount of seconds in this duration. intcompareTo(Duration duration)Compares 2 duration objects. StringtoString()Returns a String representation of this object. -
-
Method Detail
-
ofNanos
static Duration ofNanos(long nanoSeconds)
Returns a new Duration object based on amount of nanoseconds.
- Parameters:
nanoSeconds- duration in nanoseconds.
-
ofMillis
static Duration ofMillis(long milliSeconds)
Returns a new Duration object based on amount of milliseconds.
- Parameters:
milliSeconds- duration in milliseconds.
-
ofMillis
static Duration ofMillis(double milliSeconds)
Returns a new Duration object based on amount of fractional milliseconds.
- Parameters:
milliSeconds- duration in milliseconds.
-
ofSeconds
static Duration ofSeconds(double seconds)
Returns a new Duration object based on amount of fractional seconds.
- Parameters:
seconds- duration in seconds.
-
toNanos
long toNanos()
Returns the amount of nanoseconds in this duration.
-
toMillis
int toMillis()
Returns the amount of milliseconds in this duration.
-
toMillisFractional
double toMillisFractional()
Returns the amount of milliseconds in this duration.
-
toSeconds
double toSeconds()
Returns the amount of seconds in this duration.
-
compareTo
int compareTo(Duration duration)
Compares 2 duration objects.
- Parameters:
duration- another duration to be compared.
-
-
-
-