Modifier and Type  Field and Description 

static Duration 
ZERO
Constant for a duration of zero.

Modifier and Type  Method and Description 

Duration 
abs()
Returns a copy of this duration with a positive length.

int 
compareTo(Duration otherDuration)
Compares this duration to the specified
Duration . 
Duration 
dividedBy(long divisor)
Returns a copy of this duration divided by the specified value.

boolean 
equals(java.lang.Object obj)
Checks if this duration is equal to the specified
Duration . 
int 
hashCode()
A hash code for this duration.

boolean 
isNegative()
Checks if this duration is negative, excluding zero.

boolean 
isZero()
Checks if this duration is zero length.

Duration 
minus(Duration duration)
Returns a copy of this duration with the specified duration subtracted.

Duration 
minusDays(long daysToSubtract)
Returns a copy of this duration with the specified duration in standard 24 hour days subtracted.

Duration 
minusHours(long hoursToSubtract)
Returns a copy of this duration with the specified duration in hours subtracted.

Duration 
minusMillis(long millisToSubtract)
Returns a copy of this duration with the specified duration in milliseconds subtracted.

Duration 
minusMinutes(long minutesToSubtract)
Returns a copy of this duration with the specified duration in minutes subtracted.

Duration 
minusSeconds(long secondsToSubtract)
Returns a copy of this duration with the specified duration in seconds subtracted.

Duration 
multipliedBy(long multiplicand)
Returns a copy of this duration multiplied by the scalar.

Duration 
negated()
Returns a copy of this duration with the length negated.

static Duration 
ofDays(long days)
Obtains a
Duration representing a number of standard 24 hour days. 
static Duration 
ofHours(long hours)
Obtains a
Duration representing a number of standard hours. 
static Duration 
ofMillis(long millis)
Obtains a
Duration representing a number of milliseconds. 
static Duration 
ofMinutes(long minutes)
Obtains a
Duration representing a number of standard minutes. 
static Duration 
ofSeconds(long seconds)
Obtains a
Duration representing a number of standard seconds. 
Duration 
plus(Duration duration)
Returns a copy of this duration with the specified duration added.

Duration 
plusDays(long daysToAdd)
Returns a copy of this duration with the specified duration in standard 24 hour days added.

Duration 
plusHours(long hoursToAdd)
Returns a copy of this duration with the specified duration in hours added.

Duration 
plusMillis(long millisToAdd)
Returns a copy of this duration with the specified duration in milliseconds added.

Duration 
plusMinutes(long minutesToAdd)
Returns a copy of this duration with the specified duration in minutes added.

Duration 
plusSeconds(long secondsToAdd)
Returns a copy of this duration with the specified duration in seconds added.

long 
toDays()
Gets the number of days in this duration.

long 
toHours()
Gets the number of hours in this duration.

long 
toMillis()
Gets the number of milliseconds in this duration.

long 
toMinutes()
Gets the number of minutes in this duration.

long 
toSeconds()
Gets the number of seconds in this duration.

java.lang.String 
toString()
A string representation of this duration using ISO8601 seconds based representation, such as
PT8H6M12.345S . 
public static final Duration ZERO
public static Duration ofDays(long days)
Duration
representing a number of standard 24 hour days.
The milliseconds are calculated based on the standard definition of a day, where each day is 86400 * 1000L milliseconds which implies a 24 hour day.
days
 the number of days, positive or negativeDuration
, not nulljava.lang.ArithmeticException
 if the input days exceeds the capacity of Duration
public static Duration ofHours(long hours)
Duration
representing a number of standard hours.
The milliseconds are calculated based on the standard definition of an hour, where each hour is 3600 * 1000L milliseconds.
hours
 the number of hours, positive or negativeDuration
, not nulljava.lang.ArithmeticException
 if the input hours exceeds the capacity of Duration
public static Duration ofMinutes(long minutes)
Duration
representing a number of standard minutes.
The milliseconds are calculated based on the standard definition of a minute, where each minute is 60 * 1000L milliseconds.
minutes
 the number of minutes, positive or negativeDuration
, not nulljava.lang.ArithmeticException
 if the input minutes exceeds the capacity of Duration
public static Duration ofSeconds(long seconds)
Duration
representing a number of standard seconds.
The milliseconds are calculated based on the standard definition of a minute, where each second is 1000L milliseconds.
seconds
 the number of seconds, positive or negativeDuration
, not nullpublic static Duration ofMillis(long millis)
Duration
representing a number of milliseconds.millis
 the number of milliseconds, positive or negativeDuration
, not nullpublic boolean isZero()
A Duration
represents a directed distance between two points on the timeline and can therefore be
positive, zero or negative. This method checks whether the length is zero.
public boolean isNegative()
A Duration
represents a directed distance between two points on the timeline and can therefore be
positive, zero or negative. This method checks whether the length is less than zero.
public Duration plus(Duration duration)
This instance is immutable and unaffected by this method call.
duration
 the duration to add, positive or negative, not nullDuration
based on this duration with the specified duration added, not nulljava.lang.ArithmeticException
 if numeric overflow occurspublic Duration plusDays(long daysToAdd)
The number of days is multiplied by 86400 * 1000L to obtain the number of milliseconds to add. This is based on the standard definition of a day as 24 hours.
This instance is immutable and unaffected by this method call.
daysToAdd
 the days to add, positive or negativeDuration
based on this duration with the specified days added, not nulljava.lang.ArithmeticException
 if numeric overflow occurspublic Duration plusHours(long hoursToAdd)
This instance is immutable and unaffected by this method call.
hoursToAdd
 the hours to add, positive or negativeDuration
based on this duration with the specified hours added, not nulljava.lang.ArithmeticException
 if numeric overflow occurspublic Duration plusMinutes(long minutesToAdd)
This instance is immutable and unaffected by this method call.
minutesToAdd
 the minutes to add, positive or negativeDuration
based on this duration with the specified minutes added, not nulljava.lang.ArithmeticException
 if numeric overflow occurspublic Duration plusSeconds(long secondsToAdd)
This instance is immutable and unaffected by this method call.
secondsToAdd
 the seconds to add, positive or negativeDuration
based on this duration with the specified seconds added, not nulljava.lang.ArithmeticException
 if numeric overflow occurspublic Duration plusMillis(long millisToAdd)
This instance is immutable and unaffected by this method call.
millisToAdd
 the milliseconds to add, positive or negativeDuration
based on this duration with the specified milliseconds added, not nulljava.lang.ArithmeticException
 if numeric overflow occurspublic Duration minus(Duration duration)
This instance is immutable and unaffected by this method call.
duration
 the duration to subtract, positive or negative, not nullDuration
based on this duration with the specified duration subtracted, not nulljava.lang.ArithmeticException
 if numeric overflow occurspublic Duration minusDays(long daysToSubtract)
The number of days is multiplied by 86400 * 1000L to obtain the number of milliseconds to subtract. This is based on the standard definition of a day as 24 hours.
This instance is immutable and unaffected by this method call.
daysToSubtract
 the days to subtract, positive or negativeDuration
based on this duration with the specified days subtracted, not nulljava.lang.ArithmeticException
 if numeric overflow occurspublic Duration minusHours(long hoursToSubtract)
This instance is immutable and unaffected by this method call.
hoursToSubtract
 the hours to subtract, positive or negativeDuration
based on this duration with the specified hours subtracted, not nulljava.lang.ArithmeticException
 if numeric overflow occurspublic Duration minusMinutes(long minutesToSubtract)
This instance is immutable and unaffected by this method call.
minutesToSubtract
 the minutes to subtract, positive or negativeDuration
based on this duration with the specified minutes subtracted, not nulljava.lang.ArithmeticException
 if numeric overflow occurspublic Duration minusSeconds(long secondsToSubtract)
This instance is immutable and unaffected by this method call.
secondsToSubtract
 the seconds to subtract, positive or negativeDuration
based on this duration with the specified seconds subtracted, not nulljava.lang.ArithmeticException
 if numeric overflow occurspublic Duration minusMillis(long millisToSubtract)
This instance is immutable and unaffected by this method call.
millisToSubtract
 the milliseconds to subtract, positive or negativeDuration
based on this duration with the specified milliseconds subtracted, not nulljava.lang.ArithmeticException
 if numeric overflow occurspublic Duration multipliedBy(long multiplicand)
This instance is immutable and unaffected by this method call.
multiplicand
 the value to multiply the duration by, positive or negativeDuration
based on this duration multiplied by the specified scalar, not nulljava.lang.ArithmeticException
 if numeric overflow occurspublic Duration dividedBy(long divisor)
This instance is immutable and unaffected by this method call.
divisor
 the value to divide the duration by, positive or negative, not zeroDuration
based on this duration divided by the specified divisor, not nulljava.lang.ArithmeticException
 if the divisor is zero or if numeric overflow occurspublic Duration negated()
This method swaps the sign of the total length of this duration. For example, PT1.3S
will be returned as
PT1.3S
.
This instance is immutable and unaffected by this method call.
Duration
based on this duration with the amount negated, not nulljava.lang.ArithmeticException
 if numeric overflow occurspublic Duration abs()
This method returns a positive duration by effectively removing the sign from any negative total length. For
example, PT1.3S
will be returned as PT1.3S
.
This instance is immutable and unaffected by this method call.
Duration
based on this duration with an absolute length, not nulljava.lang.ArithmeticException
 if numeric overflow occurspublic long toDays()
This returns the total number of days in the duration by dividing the number of milliseconds by 86400 * 1000L. This is based on the standard definition of a day as 24 hours.
This instance is immutable and unaffected by this method call.
public long toHours()
This instance is immutable and unaffected by this method call.
public long toMinutes()
This instance is immutable and unaffected by this method call.
public long toSeconds()
This instance is immutable and unaffected by this method call.
public long toMillis()
This instance is immutable and unaffected by this method call.
java.lang.ArithmeticException
 if numeric overflow occurspublic int compareTo(Duration otherDuration)
Duration
.
The comparison is based on the total length of the durations. It is "consistent with equals", as defined by
Comparable
.
compareTo
in interface java.lang.Comparable<Duration>
otherDuration
 the other duration to compare to, not nullpublic boolean equals(java.lang.Object obj)
Duration
.
The comparison is based on the total length of the durations.
equals
in class java.lang.Object
obj
 the other duration, null returns falsepublic int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
PT8H6M12.345S
.
The format of the returned string will be PTnHnMnS
, where n is the relevant hours, minutes or seconds
part of the duration. Any fractional seconds are placed after a decimal point i the seconds section. If a section
has a zero value, it is omitted. The hours, minutes and seconds will all have the same sign.
Examples:
"20.345 seconds"  "PT20.345S "15 minutes" (15 * 60 seconds)  "PT15M" "10 hours" (10 * 3600 seconds)  "PT10H" "2 days" (2 * 86400 seconds)  "PT48H"Note that multiples of 24 hours are not output as days to avoid confusion with
Period
.toString
in class java.lang.Object