# Duration

## User guide for the Duration class

The `Duration` class represents a duration between two instants on the time-line.

A physical duration could be of infinite length. The duration is measured in “seconds” with nanosecond precision, 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.

#### Creating a Duration

##### As difference between two instants

Common usage of creating a duration is to give two instants and find the duration between them.

When end-Instant is earlier than that of start-Instant, the duration will be negative

##### Using factory methods

Duration object can also be obtained using the following factory methods.

The first method, (a), obtains a duration from the value of `ChronoUnit` and the type passed. In this example we are passing one minute which is equivalent to 60 seconds.

The second method, (b), obtains a duration from a number of nanoseconds. Nanoseconds is one billionth of a second and hence 1 second = 1000,000,000 nanos.

The third method, (c), obtains a duration from a number of milliseconds. 1 second = 1000 milliseconds.

The fourth method, (d), obtains a duration from a number of seconds. Here, the nanoseconds is set to zero.

The fifth method, (e), obtains a duration from a number of seconds and an adjustment in nanoseconds.

The sixth method, (f), obtains a duration from a number of minutes. Each minute is 60 seconds. Here, the nanoseconds is set to zero.

The seventh method, (g), obtains a duration from a number of hours. Each hour is 3600 seconds. Here, the nanoseconds is set to zero.

The eighth method, (h), obtains a duration from a number of days. Each day is 86400 seconds which implies a 24 hour day. Here, the nanoseconds is set to zero.

The ninth method, (i), obtains a duration by parsing the text passed. This will parse the string produced by toString() which is the ISO-8601 format PTnS where n is the number of seconds with optional decimal part. The number must consist of ASCII numerals. There must only be a negative sign at the start of the number and it can only be present if the value is less than zero. There must be at least one digit before any decimal point. There must be between 1 and 9 inclusive digits after any decimal point. The letters (P, T and S) will be accepted in upper or lower case. The decimal point may be either a dot or a comma.