# Duration

public final class **Duration** extends [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)  
implements [TemporalAmount](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/TemporalAmount.html) [Comparable](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Comparable.html)\<[Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html)\> [Serializable](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Serializable.html) A time-based amount of time, such as '34.5 seconds'.


This class models a quantity or amount of time in terms of seconds and nanoseconds.
It can be accessed using other duration-based units, such as minutes and hours.
In addition, the `https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/ChronoUnit.html#DAYS` unit can be used and is treated as
exactly equal to 24 hours, thus ignoring daylight savings effects.
See `https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Period.html` for the date-based equivalent to this class.


A physical duration could be of infinite length.
For practicality, the duration is stored with constraints similar to `https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Instant.html`.
The duration uses nanosecond resolution with a maximum value of the seconds that can
be held in a `long`. This is greater than the current estimated age of the universe.


The range of a duration requires the storage of a number larger than a `long`.
To achieve this, the class stores a `long` representing seconds and an `int`
representing nanosecond-of-second, which will always be between 0 and 999,999,999.
The model is of a directed duration, meaning that the duration may be negative.


The duration is measured in "seconds", but these are not necessarily identical to
the scientific "SI second" definition based on atomic clocks.
This difference only impacts durations measured near a leap-second and should not affect
most applications.
See `https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Instant.html` for a discussion as to the meaning of the second and time-scales.

### Field Summary

|---|---|---|
| public static final [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html) | [ZERO](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#ZERO) | Constant for a duration of zero. |

### Public Method Summary

|---|---|
| [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html) | [abs](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#abs())() Returns a copy of this duration with a positive length. |
| [Temporal](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/Temporal.html) | [addTo](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#addTo(java.time.temporal.Temporal))([Temporal](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/Temporal.html) temporal) Adds this duration to the specified temporal object. |
| static [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html) | [between](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#between(java.time.temporal.Temporal,%20java.time.temporal.Temporal))([Temporal](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/Temporal.html) startInclusive, [Temporal](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/Temporal.html) endExclusive) Obtains a `Duration` representing the duration between two temporal objects. |
| int | [compareTo](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#compareTo(java.time.Duration))([Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html) otherDuration) Compares this duration to the specified `Duration`. |
| [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html) | [dividedBy](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#dividedBy(long))(long divisor) Returns a copy of this duration divided by the specified value. |
| boolean | [equals](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#equals(java.lang.Object))([Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) otherDuration) Checks if this duration is equal to the specified `Duration`. |
| static [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html) | [from](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#from(java.time.temporal.TemporalAmount))([TemporalAmount](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/TemporalAmount.html) amount) Obtains an instance of `Duration` from a temporal amount. |
| long | [get](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#get(java.time.temporal.TemporalUnit))([TemporalUnit](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/TemporalUnit.html) unit) Gets the value of the requested unit. |
| int | [getNano](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#getNano())() Gets the number of nanoseconds within the second in this duration. |
| long | [getSeconds](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#getSeconds())() Gets the number of seconds in this duration. |
| [List](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/List.html)\<[TemporalUnit](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/TemporalUnit.html)\> | [getUnits](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#getUnits())() Gets the set of units supported by this duration. |
| int | [hashCode](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#hashCode())() A hash code for this duration. |
| boolean | [isNegative](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#isNegative())() Checks if this duration is negative, excluding zero. |
| boolean | [isZero](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#isZero())() Checks if this duration is zero length. |
| [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html) | [minus](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#minus(java.time.Duration))([Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html) duration) Returns a copy of this duration with the specified duration subtracted. |
| [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html) | [minus](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#minus(long,%20java.time.temporal.TemporalUnit))(long amountToSubtract, [TemporalUnit](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/TemporalUnit.html) unit) Returns a copy of this duration with the specified duration subtracted. |
| [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html) | [minusDays](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#minusDays(long))(long daysToSubtract) Returns a copy of this duration with the specified duration in standard 24 hour days subtracted. |
| [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html) | [minusHours](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#minusHours(long))(long hoursToSubtract) Returns a copy of this duration with the specified duration in hours subtracted. |
| [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html) | [minusMillis](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#minusMillis(long))(long millisToSubtract) Returns a copy of this duration with the specified duration in milliseconds subtracted. |
| [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html) | [minusMinutes](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#minusMinutes(long))(long minutesToSubtract) Returns a copy of this duration with the specified duration in minutes subtracted. |
| [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html) | [minusNanos](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#minusNanos(long))(long nanosToSubtract) Returns a copy of this duration with the specified duration in nanoseconds subtracted. |
| [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html) | [minusSeconds](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#minusSeconds(long))(long secondsToSubtract) Returns a copy of this duration with the specified duration in seconds subtracted. |
| [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html) | [multipliedBy](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#multipliedBy(long))(long multiplicand) Returns a copy of this duration multiplied by the scalar. |
| [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html) | [negated](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#negated())() Returns a copy of this duration with the length negated. |
| static [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html) | [of](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#of(long,%20java.time.temporal.TemporalUnit))(long amount, [TemporalUnit](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/TemporalUnit.html) unit) Obtains a `Duration` representing an amount in the specified unit. |
| static [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html) | [ofDays](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#ofDays(long))(long days) Obtains a `Duration` representing a number of standard 24 hour days. |
| static [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html) | [ofHours](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#ofHours(long))(long hours) Obtains a `Duration` representing a number of standard hours. |
| static [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html) | [ofMillis](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#ofMillis(long))(long millis) Obtains a `Duration` representing a number of milliseconds. |
| static [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html) | [ofMinutes](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#ofMinutes(long))(long minutes) Obtains a `Duration` representing a number of standard minutes. |
| static [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html) | [ofNanos](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#ofNanos(long))(long nanos) Obtains a `Duration` representing a number of nanoseconds. |
| static [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html) | [ofSeconds](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#ofSeconds(long,%20long))(long seconds, long nanoAdjustment) Obtains a `Duration` representing a number of seconds and an adjustment in nanoseconds. |
| static [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html) | [ofSeconds](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#ofSeconds(long))(long seconds) Obtains a `Duration` representing a number of seconds. |
| static [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html) | [parse](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#parse(java.lang.CharSequence))([CharSequence](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/CharSequence.html) text) Obtains a `Duration` from a text string such as `PnDTnHnMn.nS`. |
| [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html) | [plus](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#plus(java.time.Duration))([Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html) duration) Returns a copy of this duration with the specified duration added. |
| [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html) | [plus](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#plus(long,%20java.time.temporal.TemporalUnit))(long amountToAdd, [TemporalUnit](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/TemporalUnit.html) unit) Returns a copy of this duration with the specified duration added. |
| [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html) | [plusDays](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#plusDays(long))(long daysToAdd) Returns a copy of this duration with the specified duration in standard 24 hour days added. |
| [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html) | [plusHours](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#plusHours(long))(long hoursToAdd) Returns a copy of this duration with the specified duration in hours added. |
| [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html) | [plusMillis](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#plusMillis(long))(long millisToAdd) Returns a copy of this duration with the specified duration in milliseconds added. |
| [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html) | [plusMinutes](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#plusMinutes(long))(long minutesToAdd) Returns a copy of this duration with the specified duration in minutes added. |
| [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html) | [plusNanos](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#plusNanos(long))(long nanosToAdd) Returns a copy of this duration with the specified duration in nanoseconds added. |
| [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html) | [plusSeconds](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#plusSeconds(long))(long secondsToAdd) Returns a copy of this duration with the specified duration in seconds added. |
| [Temporal](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/Temporal.html) | [subtractFrom](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#subtractFrom(java.time.temporal.Temporal))([Temporal](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/Temporal.html) temporal) Subtracts this duration from the specified temporal object. |
| long | [toDays](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#toDays())() Gets the number of days in this duration. |
| long | [toHours](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#toHours())() Gets the number of hours in this duration. |
| long | [toMillis](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#toMillis())() Converts this duration to the total length in milliseconds. |
| long | [toMinutes](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#toMinutes())() Gets the number of minutes in this duration. |
| long | [toNanos](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#toNanos())() Converts this duration to the total length in nanoseconds expressed as a `long`. |
| [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [toString](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#toString())() A string representation of this duration using ISO-8601 seconds based representation, such as `PT8H6M12.345S`. |
| [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html) | [withNanos](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#withNanos(int))(int nanoOfSecond) Returns a copy of this duration with the specified nano-of-second. |
| [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html) | [withSeconds](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#withSeconds(long))(long seconds) Returns a copy of this duration with the specified amount of seconds. |

### Inherited Method Summary

From class [java.lang.Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)

|---|---|
| [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) | [clone](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#clone())() Creates and returns a copy of this `Object`. |
| boolean | [equals](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#equals(java.lang.Object))([Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) obj) Compares this instance with the specified object and indicates if they are equal. |
| void | [finalize](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#finalize())() Invoked when the garbage collector has detected that this instance is no longer reachable. |
| final [Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<?\> | [getClass](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#getClass())() Returns the unique instance of `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html` that represents this object's class. |
| int | [hashCode](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#hashCode())() Returns an integer hash code for this object. |
| final void | [notify](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notify())() Causes a thread which is waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| final void | [notifyAll](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notifyAll())() Causes all threads which are waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [toString](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#toString())() Returns a string containing a concise, human-readable description of this object. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long,%20int))(long timeout, int nanos) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long))(long timeout) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait())() Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object. |

From interface [java.time.temporal.TemporalAmount](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/TemporalAmount.html)

|---|---|
| abstract [Temporal](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/Temporal.html) | [addTo](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/TemporalAmount.html#addTo(java.time.temporal.Temporal))([Temporal](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/Temporal.html) temporal) Adds to the specified temporal object. |
| abstract long | [get](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/TemporalAmount.html#get(java.time.temporal.TemporalUnit))([TemporalUnit](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/TemporalUnit.html) unit) Returns the value of the requested unit. |
| abstract [List](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/List.html)\<[TemporalUnit](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/TemporalUnit.html)\> | [getUnits](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/TemporalAmount.html#getUnits())() Returns the list of units uniquely defining the value of this TemporalAmount. |
| abstract [Temporal](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/Temporal.html) | [subtractFrom](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/TemporalAmount.html#subtractFrom(java.time.temporal.Temporal))([Temporal](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/Temporal.html) temporal) Subtracts this object from the specified temporal object. |

From interface [java.lang.Comparable](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Comparable.html)

|---|---|
| abstract int | [compareTo](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Comparable.html#compareTo(T))([Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html) o) Compares this object with the specified object for order. |

## Fields

#### public static final Duration
**ZERO**

Constant for a duration of zero.

## Public Methods

#### public [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html)
**abs**
()

Returns a copy of this duration with a positive length.


This method returns a positive duration by effectively removing the sign from any negative total length.
For example, `PT-1.3S` will be returned as `PT1.3S`.


This instance is immutable and unaffected by this method call.

##### Returns

- a `Duration` based on this duration with an absolute length, not null

##### Throws

| [ArithmeticException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/ArithmeticException.html) | if numeric overflow occurs |
|---|---|

#### public [Temporal](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/Temporal.html)
**addTo**
([Temporal](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/Temporal.html) temporal)

Adds this duration to the specified temporal object.


This returns a temporal object of the same observable type as the input
with this duration added.


In most cases, it is clearer to reverse the calling pattern by using
`https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/Temporal.html#plus(java.time.temporal.TemporalAmount)`.

```
   // these two lines are equivalent, but the second approach is recommended
   dateTime = thisDuration.addTo(dateTime);
   dateTime = dateTime.plus(thisDuration);
 
```


The calculation will add the seconds, then nanos.
Only non-zero amounts will be added.


This instance is immutable and unaffected by this method call.

##### Parameters

| temporal | the temporal object to adjust, not null |
|---|---|

##### Returns

- an object of the same type with the adjustment made, not null

##### Throws

| [DateTimeException](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/DateTimeException.html) | if unable to add |
| [ArithmeticException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/ArithmeticException.html) | if numeric overflow occurs |
|---|---|

#### public static [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html)
**between**
([Temporal](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/Temporal.html) startInclusive, [Temporal](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/Temporal.html) endExclusive)

Obtains a `Duration` representing the duration between two temporal objects.


This calculates the duration between two temporal objects. If the objects
are of different types, then the duration is calculated based on the type
of the first object. For example, if the first argument is a `LocalTime`
then the second argument is converted to a `LocalTime`.


The specified temporal objects must support the `https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/ChronoUnit.html#SECONDS` unit.
For full accuracy, either the `https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/ChronoUnit.html#NANOS` unit or the
`https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/ChronoField.html#NANO_OF_SECOND` field should be supported.


The result of this method can be a negative period if the end is before the start.
To guarantee to obtain a positive duration call `https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#abs()` on the result.

##### Parameters

| startInclusive | the start instant, inclusive, not null |
| endExclusive | the end instant, exclusive, not null |
|---|---|

##### Returns

- a `Duration`, not null

##### Throws

| [DateTimeException](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/DateTimeException.html) | if the seconds between the temporals cannot be obtained |
| [ArithmeticException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/ArithmeticException.html) | if the calculation exceeds the capacity of `Duration` |
|---|---|

#### public int
**compareTo**
([Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html) otherDuration)

Compares this duration to the specified `Duration`.


The comparison is based on the total length of the durations.
It is "consistent with equals", as defined by `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Comparable.html`.

##### Parameters

| otherDuration | the other duration to compare to, not null |
|---|---|

##### Returns

- the comparator value, negative if less, positive if greater

#### public [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html)
**dividedBy**
(long divisor)

Returns a copy of this duration divided by the specified value.


This instance is immutable and unaffected by this method call.

##### Parameters

| divisor | the value to divide the duration by, positive or negative, not zero |
|---|---|

##### Returns

- a `Duration` based on this duration divided by the specified divisor, not null

##### Throws

| [ArithmeticException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/ArithmeticException.html) | if the divisor is zero or if numeric overflow occurs |
|---|---|

#### public boolean
**equals**
([Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) otherDuration)

Checks if this duration is equal to the specified `Duration`.


The comparison is based on the total length of the durations.

##### Parameters

| otherDuration | the other duration, null returns false |
|---|---|

##### Returns

- true if the other duration is equal to this one

#### public static [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html)
**from**
([TemporalAmount](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/TemporalAmount.html) amount)

Obtains an instance of `Duration` from a temporal amount.


This obtains a duration based on the specified amount.
A `TemporalAmount` represents an amount of time, which may be
date-based or time-based, which this factory extracts to a duration.


The conversion loops around the set of units from the amount and uses
the {@linkplain TemporalUnit#getDuration() duration} of the unit to
calculate the total `Duration`.
Only a subset of units are accepted by this method. The unit must either
have an {@linkplain TemporalUnit#isDurationEstimated() exact duration}
or be `https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/ChronoUnit.html#DAYS` which is treated as 24 hours.
If any other units are found then an exception is thrown.

##### Parameters

| amount | the temporal amount to convert, not null |
|---|---|

##### Returns

- the equivalent duration, not null

##### Throws

| [DateTimeException](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/DateTimeException.html) | if unable to convert to a `Duration` |
| [ArithmeticException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/ArithmeticException.html) | if numeric overflow occurs |
|---|---|

#### public long
**get**
([TemporalUnit](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/TemporalUnit.html) unit)

Gets the value of the requested unit.


This returns a value for each of the two supported units,
`https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/ChronoUnit.html#SECONDS` and `https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/ChronoUnit.html#NANOS`.
All other units throw an exception.

##### Parameters

| unit | the `TemporalUnit` for which to return the value |
|---|---|

##### Returns

- the long value of the unit

##### Throws

| [DateTimeException](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/DateTimeException.html) | if the unit is not supported |
| [UnsupportedTemporalTypeException](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/UnsupportedTemporalTypeException.html) | if the unit is not supported |
|---|---|

#### public int
**getNano**
()

Gets the number of nanoseconds within the second in this duration.


The length of the duration is stored using two fields - seconds and nanoseconds.
The nanoseconds part is a value from 0 to 999,999,999 that is an adjustment to
the length in seconds.
The total duration is defined by calling this method and `https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#getSeconds()`.


A `Duration` represents a directed distance between two points on the time-line.
A negative duration is expressed by the negative sign of the seconds part.
A duration of -1 nanosecond is stored as -1 seconds plus 999,999,999 nanoseconds.

##### Returns

- the nanoseconds within the second part of the length of the duration, from 0 to 999,999,999

#### public long
**getSeconds**
()

Gets the number of seconds in this duration.


The length of the duration is stored using two fields - seconds and nanoseconds.
The nanoseconds part is a value from 0 to 999,999,999 that is an adjustment to
the length in seconds.
The total duration is defined by calling this method and `https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#getNano()`.


A `Duration` represents a directed distance between two points on the time-line.
A negative duration is expressed by the negative sign of the seconds part.
A duration of -1 nanosecond is stored as -1 seconds plus 999,999,999 nanoseconds.

##### Returns

- the whole seconds part of the length of the duration, positive or negative

#### public [List](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/List.html)\<[TemporalUnit](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/TemporalUnit.html)\>
**getUnits**
()

Gets the set of units supported by this duration.


The supported units are `https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/ChronoUnit.html#SECONDS`,
and `https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/ChronoUnit.html#NANOS`.
They are returned in the order seconds, nanos.


This set can be used in conjunction with `https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html#get(java.time.temporal.TemporalUnit)`
to access the entire state of the duration.

##### Returns

- a list containing the seconds and nanos units, not null

#### public int
**hashCode**
()

A hash code for this duration.

##### Returns

- a suitable hash code

#### public boolean
**isNegative**
()

Checks if this duration is negative, excluding zero.


A `Duration` represents a directed distance between two points on
the time-line and can therefore be positive, zero or negative.
This method checks whether the length is less than zero.

##### Returns

- true if this duration has a total length less than zero

#### public boolean
**isZero**
()

Checks if this duration is zero length.


A `Duration` represents a directed distance between two points on
the time-line and can therefore be positive, zero or negative.
This method checks whether the length is zero.

##### Returns

- true if this duration has a total length equal to zero

#### public [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html)
**minus**
([Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html) duration)

Returns a copy of this duration with the specified duration subtracted.


This instance is immutable and unaffected by this method call.

##### Parameters

| duration | the duration to subtract, positive or negative, not null |
|---|---|

##### Returns

- a `Duration` based on this duration with the specified duration subtracted, not null

##### Throws

| [ArithmeticException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/ArithmeticException.html) | if numeric overflow occurs |
|---|---|

#### public [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html)
**minus**
(long amountToSubtract, [TemporalUnit](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/TemporalUnit.html) unit)

Returns a copy of this duration with the specified duration subtracted.


The duration amount is measured in terms of the specified unit.
Only a subset of units are accepted by this method.
The unit must either have an {@linkplain TemporalUnit#isDurationEstimated() exact duration} or
be `https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/ChronoUnit.html#DAYS` which is treated as 24 hours. Other units throw an exception.


This instance is immutable and unaffected by this method call.

##### Parameters

| amountToSubtract | the amount to subtract, measured in terms of the unit, positive or negative |
| unit | the unit that the amount is measured in, must have an exact duration, not null |
|---|---|

##### Returns

- a `Duration` based on this duration with the specified duration subtracted, not null

##### Throws

| [ArithmeticException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/ArithmeticException.html) | if numeric overflow occurs |
|---|---|

#### public [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html)
**minusDays**
(long daysToSubtract)

Returns a copy of this duration with the specified duration in standard 24 hour days subtracted.


The number of days is multiplied by 86400 to obtain the number of seconds 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.

##### Parameters

| daysToSubtract | the days to subtract, positive or negative |
|---|---|

##### Returns

- a `Duration` based on this duration with the specified days subtracted, not null

##### Throws

| [ArithmeticException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/ArithmeticException.html) | if numeric overflow occurs |
|---|---|

#### public [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html)
**minusHours**
(long hoursToSubtract)

Returns a copy of this duration with the specified duration in hours subtracted.


The number of hours is multiplied by 3600 to obtain the number of seconds to subtract.


This instance is immutable and unaffected by this method call.

##### Parameters

| hoursToSubtract | the hours to subtract, positive or negative |
|---|---|

##### Returns

- a `Duration` based on this duration with the specified hours subtracted, not null

##### Throws

| [ArithmeticException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/ArithmeticException.html) | if numeric overflow occurs |
|---|---|

#### public [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html)
**minusMillis**
(long millisToSubtract)

Returns a copy of this duration with the specified duration in milliseconds subtracted.


This instance is immutable and unaffected by this method call.

##### Parameters

| millisToSubtract | the milliseconds to subtract, positive or negative |
|---|---|

##### Returns

- a `Duration` based on this duration with the specified milliseconds subtracted, not null

##### Throws

| [ArithmeticException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/ArithmeticException.html) | if numeric overflow occurs |
|---|---|

#### public [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html)
**minusMinutes**
(long minutesToSubtract)

Returns a copy of this duration with the specified duration in minutes subtracted.


The number of hours is multiplied by 60 to obtain the number of seconds to subtract.


This instance is immutable and unaffected by this method call.

##### Parameters

| minutesToSubtract | the minutes to subtract, positive or negative |
|---|---|

##### Returns

- a `Duration` based on this duration with the specified minutes subtracted, not null

##### Throws

| [ArithmeticException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/ArithmeticException.html) | if numeric overflow occurs |
|---|---|

#### public [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html)
**minusNanos**
(long nanosToSubtract)

Returns a copy of this duration with the specified duration in nanoseconds subtracted.


This instance is immutable and unaffected by this method call.

##### Parameters

| nanosToSubtract | the nanoseconds to subtract, positive or negative |
|---|---|

##### Returns

- a `Duration` based on this duration with the specified nanoseconds subtracted, not null

##### Throws

| [ArithmeticException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/ArithmeticException.html) | if numeric overflow occurs |
|---|---|

#### public [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html)
**minusSeconds**
(long secondsToSubtract)

Returns a copy of this duration with the specified duration in seconds subtracted.


This instance is immutable and unaffected by this method call.

##### Parameters

| secondsToSubtract | the seconds to subtract, positive or negative |
|---|---|

##### Returns

- a `Duration` based on this duration with the specified seconds subtracted, not null

##### Throws

| [ArithmeticException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/ArithmeticException.html) | if numeric overflow occurs |
|---|---|

#### public [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html)
**multipliedBy**
(long multiplicand)

Returns a copy of this duration multiplied by the scalar.


This instance is immutable and unaffected by this method call.

##### Parameters

| multiplicand | the value to multiply the duration by, positive or negative |
|---|---|

##### Returns

- a `Duration` based on this duration multiplied by the specified scalar, not null

##### Throws

| [ArithmeticException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/ArithmeticException.html) | if numeric overflow occurs |
|---|---|

#### public [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html)
**negated**
()

Returns a copy of this duration with the length negated.


This method swaps the sign of the total length of this duration.
For example, `PT1.3S` will be returned as `PT-1.3S`.


This instance is immutable and unaffected by this method call.

##### Returns

- a `Duration` based on this duration with the amount negated, not null

##### Throws

| [ArithmeticException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/ArithmeticException.html) | if numeric overflow occurs |
|---|---|

#### public static [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html)
**of**
(long amount, [TemporalUnit](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/TemporalUnit.html) unit)

Obtains a `Duration` representing an amount in the specified unit.


The parameters represent the two parts of a phrase like '6 Hours'. For example:

```
  Duration.of(3, SECONDS);
  Duration.of(465, HOURS);
 
```
Only a subset of units are accepted by this method. The unit must either have an {@linkplain TemporalUnit#isDurationEstimated() exact duration} or be `https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/ChronoUnit.html#DAYS` which is treated as 24 hours. Other units throw an exception.

<br />

##### Parameters

| amount | the amount of the duration, measured in terms of the unit, positive or negative |
| unit | the unit that the duration is measured in, must have an exact duration, not null |
|---|---|

##### Returns

- a `Duration`, not null

##### Throws

| [DateTimeException](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/DateTimeException.html) | if the period unit has an estimated duration |
| [ArithmeticException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/ArithmeticException.html) | if a numeric overflow occurs |
|---|---|

#### public static [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html)
**ofDays**
(long days)

Obtains a `Duration` representing a number of standard 24 hour days.


The seconds are calculated based on the standard definition of a day,
where each day is 86400 seconds which implies a 24 hour day.
The nanosecond in second field is set to zero.

##### Parameters

| days | the number of days, positive or negative |
|---|---|

##### Returns

- a `Duration`, not null

##### Throws

| [ArithmeticException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/ArithmeticException.html) | if the input days exceeds the capacity of `Duration` |
|---|---|

#### public static [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html)
**ofHours**
(long hours)

Obtains a `Duration` representing a number of standard hours.


The seconds are calculated based on the standard definition of an hour,
where each hour is 3600 seconds.
The nanosecond in second field is set to zero.

##### Parameters

| hours | the number of hours, positive or negative |
|---|---|

##### Returns

- a `Duration`, not null

##### Throws

| [ArithmeticException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/ArithmeticException.html) | if the input hours exceeds the capacity of `Duration` |
|---|---|

#### public static [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html)
**ofMillis**
(long millis)

Obtains a `Duration` representing a number of milliseconds.


The seconds and nanoseconds are extracted from the specified milliseconds.

##### Parameters

| millis | the number of milliseconds, positive or negative |
|---|---|

##### Returns

- a `Duration`, not null

#### public static [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html)
**ofMinutes**
(long minutes)

Obtains a `Duration` representing a number of standard minutes.


The seconds are calculated based on the standard definition of a minute,
where each minute is 60 seconds.
The nanosecond in second field is set to zero.

##### Parameters

| minutes | the number of minutes, positive or negative |
|---|---|

##### Returns

- a `Duration`, not null

##### Throws

| [ArithmeticException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/ArithmeticException.html) | if the input minutes exceeds the capacity of `Duration` |
|---|---|

#### public static [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html)
**ofNanos**
(long nanos)

Obtains a `Duration` representing a number of nanoseconds.


The seconds and nanoseconds are extracted from the specified nanoseconds.

##### Parameters

| nanos | the number of nanoseconds, positive or negative |
|---|---|

##### Returns

- a `Duration`, not null

#### public static [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html)
**ofSeconds**
(long seconds, long nanoAdjustment)

Obtains a `Duration` representing a number of seconds and an
adjustment in nanoseconds.


This method allows an arbitrary number of nanoseconds to be passed in.
The factory will alter the values of the second and nanosecond in order
to ensure that the stored nanosecond is in the range 0 to 999,999,999.
For example, the following will result in the exactly the same duration:

```
  Duration.ofSeconds(3, 1);
  Duration.ofSeconds(4, -999_999_999);
  Duration.ofSeconds(2, 1000_000_001);
 
```

<br />

##### Parameters

| seconds | the number of seconds, positive or negative |
| nanoAdjustment | the nanosecond adjustment to the number of seconds, positive or negative |
|---|---|

##### Returns

- a `Duration`, not null

##### Throws

| [ArithmeticException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/ArithmeticException.html) | if the adjustment causes the seconds to exceed the capacity of `Duration` |
|---|---|

#### public static [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html)
**ofSeconds**
(long seconds)

Obtains a `Duration` representing a number of seconds.


The nanosecond in second field is set to zero.

##### Parameters

| seconds | the number of seconds, positive or negative |
|---|---|

##### Returns

- a `Duration`, not null

#### public static [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html)
**parse**
([CharSequence](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/CharSequence.html) text)

Obtains a `Duration` from a text string such as `PnDTnHnMn.nS`.


This will parse a textual representation of a duration, including the
string produced by `toString()`. The formats accepted are based
on the ISO-8601 duration format `PnDTnHnMn.nS` with days
considered to be exactly 24 hours.


The string starts with an optional sign, denoted by the ASCII negative
or positive symbol. If negative, the whole period is negated.
The ASCII letter "P" is next in upper or lower case.
There are then four sections, each consisting of a number and a suffix.
The sections have suffixes in ASCII of "D", "H", "M" and "S" for
days, hours, minutes and seconds, accepted in upper or lower case.
The suffixes must occur in order. The ASCII letter "T" must occur before
the first occurrence, if any, of an hour, minute or second section.
At least one of the four sections must be present, and if "T" is present
there must be at least one section after the "T".
The number part of each section must consist of one or more ASCII digits.
The number may be prefixed by the ASCII negative or positive symbol.
The number of days, hours and minutes must parse to an `long`.
The number of seconds must parse to an `long` with optional fraction.
The decimal point may be either a dot or a comma.
The fractional part may have from zero to 9 digits.


The leading plus/minus sign, and negative values for other units are
not part of the ISO-8601 standard.


Examples:

```
    "PT20.345S" -- parses as "20.345 seconds"
    "PT15M"     -- parses as "15 minutes" (where a minute is 60 seconds)
    "PT10H"     -- parses as "10 hours" (where an hour is 3600 seconds)
    "P2D"       -- parses as "2 days" (where a day is 24 hours or 86400 seconds)
    "P2DT3H4M"  -- parses as "2 days, 3 hours and 4 minutes"
    "P-6H3M"    -- parses as "-6 hours and +3 minutes"
    "-P6H3M"    -- parses as "-6 hours and -3 minutes"
    "-P-6H+3M"  -- parses as "+6 hours and -3 minutes"
 
```

<br />

##### Parameters

| text | the text to parse, not null |
|---|---|

##### Returns

- the parsed duration, not null

##### Throws

| [DateTimeParseException](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/format/DateTimeParseException.html) | if the text cannot be parsed to a duration |
|---|---|

#### public [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html)
**plus**
([Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html) duration)

Returns a copy of this duration with the specified duration added.


This instance is immutable and unaffected by this method call.

##### Parameters

| duration | the duration to add, positive or negative, not null |
|---|---|

##### Returns

- a `Duration` based on this duration with the specified duration added, not null

##### Throws

| [ArithmeticException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/ArithmeticException.html) | if numeric overflow occurs |
|---|---|

#### public [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html)
**plus**
(long amountToAdd, [TemporalUnit](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/TemporalUnit.html) unit)

Returns a copy of this duration with the specified duration added.


The duration amount is measured in terms of the specified unit.
Only a subset of units are accepted by this method.
The unit must either have an {@linkplain TemporalUnit#isDurationEstimated() exact duration} or
be `https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/ChronoUnit.html#DAYS` which is treated as 24 hours. Other units throw an exception.


This instance is immutable and unaffected by this method call.

##### Parameters

| amountToAdd | the amount to add, measured in terms of the unit, positive or negative |
| unit | the unit that the amount is measured in, must have an exact duration, not null |
|---|---|

##### Returns

- a `Duration` based on this duration with the specified duration added, not null

##### Throws

| [UnsupportedTemporalTypeException](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/UnsupportedTemporalTypeException.html) | if the unit is not supported |
| [ArithmeticException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/ArithmeticException.html) | if numeric overflow occurs |
|---|---|

#### public [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html)
**plusDays**
(long daysToAdd)

Returns a copy of this duration with the specified duration in standard 24 hour days added.


The number of days is multiplied by 86400 to obtain the number of seconds 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.

##### Parameters

| daysToAdd | the days to add, positive or negative |
|---|---|

##### Returns

- a `Duration` based on this duration with the specified days added, not null

##### Throws

| [ArithmeticException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/ArithmeticException.html) | if numeric overflow occurs |
|---|---|

#### public [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html)
**plusHours**
(long hoursToAdd)

Returns a copy of this duration with the specified duration in hours added.


This instance is immutable and unaffected by this method call.

##### Parameters

| hoursToAdd | the hours to add, positive or negative |
|---|---|

##### Returns

- a `Duration` based on this duration with the specified hours added, not null

##### Throws

| [ArithmeticException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/ArithmeticException.html) | if numeric overflow occurs |
|---|---|

#### public [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html)
**plusMillis**
(long millisToAdd)

Returns a copy of this duration with the specified duration in milliseconds added.


This instance is immutable and unaffected by this method call.

##### Parameters

| millisToAdd | the milliseconds to add, positive or negative |
|---|---|

##### Returns

- a `Duration` based on this duration with the specified milliseconds added, not null

##### Throws

| [ArithmeticException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/ArithmeticException.html) | if numeric overflow occurs |
|---|---|

#### public [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html)
**plusMinutes**
(long minutesToAdd)

Returns a copy of this duration with the specified duration in minutes added.


This instance is immutable and unaffected by this method call.

##### Parameters

| minutesToAdd | the minutes to add, positive or negative |
|---|---|

##### Returns

- a `Duration` based on this duration with the specified minutes added, not null

##### Throws

| [ArithmeticException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/ArithmeticException.html) | if numeric overflow occurs |
|---|---|

#### public [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html)
**plusNanos**
(long nanosToAdd)

Returns a copy of this duration with the specified duration in nanoseconds added.


This instance is immutable and unaffected by this method call.

##### Parameters

| nanosToAdd | the nanoseconds to add, positive or negative |
|---|---|

##### Returns

- a `Duration` based on this duration with the specified nanoseconds added, not null

##### Throws

| [ArithmeticException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/ArithmeticException.html) | if numeric overflow occurs |
|---|---|

#### public [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html)
**plusSeconds**
(long secondsToAdd)

Returns a copy of this duration with the specified duration in seconds added.


This instance is immutable and unaffected by this method call.

##### Parameters

| secondsToAdd | the seconds to add, positive or negative |
|---|---|

##### Returns

- a `Duration` based on this duration with the specified seconds added, not null

##### Throws

| [ArithmeticException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/ArithmeticException.html) | if numeric overflow occurs |
|---|---|

#### public [Temporal](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/Temporal.html)
**subtractFrom**
([Temporal](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/Temporal.html) temporal)

Subtracts this duration from the specified temporal object.


This returns a temporal object of the same observable type as the input
with this duration subtracted.


In most cases, it is clearer to reverse the calling pattern by using
`https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/Temporal.html#minus(java.time.temporal.TemporalAmount)`.

```
   // these two lines are equivalent, but the second approach is recommended
   dateTime = thisDuration.subtractFrom(dateTime);
   dateTime = dateTime.minus(thisDuration);
 
```


The calculation will subtract the seconds, then nanos.
Only non-zero amounts will be added.


This instance is immutable and unaffected by this method call.

##### Parameters

| temporal | the temporal object to adjust, not null |
|---|---|

##### Returns

- an object of the same type with the adjustment made, not null

##### Throws

| [DateTimeException](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/DateTimeException.html) | if unable to subtract |
| [ArithmeticException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/ArithmeticException.html) | if numeric overflow occurs |
|---|---|

#### public long
**toDays**
()

Gets the number of days in this duration.


This returns the total number of days in the duration by dividing the
number of seconds by 86400.
This is based on the standard definition of a day as 24 hours.


This instance is immutable and unaffected by this method call.

##### Returns

- the number of days in the duration, may be negative

#### public long
**toHours**
()

Gets the number of hours in this duration.


This returns the total number of hours in the duration by dividing the
number of seconds by 3600.


This instance is immutable and unaffected by this method call.

##### Returns

- the number of hours in the duration, may be negative

#### public long
**toMillis**
()

Converts this duration to the total length in milliseconds.


If this duration is too large to fit in a `long` milliseconds, then an
exception is thrown.


If this duration has greater than millisecond precision, then the conversion
will drop any excess precision information as though the amount in nanoseconds
was subject to integer division by one million.

##### Returns

- the total length of the duration in milliseconds

##### Throws

| [ArithmeticException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/ArithmeticException.html) | if numeric overflow occurs |
|---|---|

#### public long
**toMinutes**
()

Gets the number of minutes in this duration.


This returns the total number of minutes in the duration by dividing the
number of seconds by 60.


This instance is immutable and unaffected by this method call.

##### Returns

- the number of minutes in the duration, may be negative

#### public long
**toNanos**
()

Converts this duration to the total length in nanoseconds expressed as a `long`.


If this duration is too large to fit in a `long` nanoseconds, then an
exception is thrown.

##### Returns

- the total length of the duration in nanoseconds

##### Throws

| [ArithmeticException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/ArithmeticException.html) | if numeric overflow occurs |
|---|---|

#### public [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html)
**toString**
()

A string representation of this duration using ISO-8601 seconds
based representation, such as `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`.

<br />

##### Returns

- an ISO-8601 representation of this duration, not null

#### public [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html)
**withNanos**
(int nanoOfSecond)

Returns a copy of this duration with the specified nano-of-second.


This returns a duration with the specified nano-of-second, retaining the
seconds part of this duration.


This instance is immutable and unaffected by this method call.

##### Parameters

| nanoOfSecond | the nano-of-second to represent, from 0 to 999,999,999 |
|---|---|

##### Returns

- a `Duration` based on this period with the requested nano-of-second, not null

##### Throws

| [DateTimeException](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/DateTimeException.html) | if the nano-of-second is invalid |
|---|---|

#### public [Duration](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/Duration.html)
**withSeconds**
(long seconds)

Returns a copy of this duration with the specified amount of seconds.


This returns a duration with the specified seconds, retaining the
nano-of-second part of this duration.


This instance is immutable and unaffected by this method call.

##### Parameters

| seconds | the seconds to represent, may be negative |
|---|---|

##### Returns

- a `Duration` based on this period with the requested seconds, not null