Interface Duration

Java Duration type.

Hierarchy

  • Duration

Properties

nanos: number

The number of nanoseconds in the duration, expressed as a fraction of the number of seconds. This is always positive, and never exceeds 999,999,999.

seconds: number

The number of seconds in the duration.

Methods

  • 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

    Throws

    ArithmeticException if numeric overflow occurs

    Returns Duration

  • 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 Comparable.

    Returns

    the comparator value, negative if less, positive if greater

    Parameters

    • otherDuration: Duration

      the other duration to compare to

    Returns number

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

    This instance is immutable and unaffected by this method call.

    Returns

    a Duration based on this duration divided by the specified divisor

    Throws

    ArithmeticException if the divisor is zero or if numeric overflow occurs

    Parameters

    • divisor: number

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

    Returns Duration

  • Returns number of whole times a specified Duration occurs within this Duration.

    This instance is immutable and unaffected by this method call.

    Returns

    number of whole times, rounded toward zero, a specified Duration occurs within this Duration, may be negative

    Throws

    ArithmeticException if the divisor is zero, or if numeric overflow occurs

    Parameters

    • divisor: Duration

      the value to divide the duration by, positive or negative

    Returns Duration

  • A hash code for this duration.

    Returns

    a suitable hash code

    Returns number

  • 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

    Returns boolean

  • 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

    Returns boolean

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

    This instance is immutable and unaffected by this method call.

    Returns

    a Duration based on this duration with the specified duration subtracted

    Throws

    ArithmeticException if numeric overflow occurs

    Parameters

    • duration: Duration

      the duration to subtract, positive or negative

    Returns Duration

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

    Returns

    a Duration based on this duration with the specified days subtracted

    Throws

    ArithmeticException if numeric overflow occurs

    Parameters

    • daysToSubtract: number

      the days to subtract, positive or negative

    Returns Duration

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

    Returns

    a Duration based on this duration with the specified hours subtracted

    Throws

    ArithmeticException if numeric overflow occurs

    Parameters

    • hoursToSubtract: number

      the hours to subtract, positive or negative

    Returns Duration

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

    This instance is immutable and unaffected by this method call.

    Returns

    a Duration based on this duration with the specified milliseconds subtracted

    Throws

    ArithmeticException if numeric overflow occurs

    Parameters

    • millisToSubtract: number

      the milliseconds to subtract, positive or negative

    Returns Duration

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

    Returns

    a Duration based on this duration with the specified minutes subtracted

    Throws

    ArithmeticException if numeric overflow occurs

    Parameters

    • minutesToSubtract: number

      the minutes to subtract, positive or negative

    Returns Duration

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

    This instance is immutable and unaffected by this method call.

    Returns

    a Duration based on this duration with the specified nanoseconds subtracted

    Throws

    ArithmeticException if numeric overflow occurs

    Parameters

    • nanosToSubtract: number

      the nanoseconds to subtract, positive or negative

    Returns Duration

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

    This instance is immutable and unaffected by this method call.

    Returns

    a Duration based on this duration with the specified seconds subtracted

    Throws

    ArithmeticException if numeric overflow occurs

    Parameters

    • secondsToSubtract: number

      the seconds to subtract, positive or negative

    Returns Duration

  • Returns a copy of this duration multiplied by the scalar.

    This instance is immutable and unaffected by this method call.

    Returns

    a Duration based on this duration multiplied by the specified scalar

    Throws

    ArithmeticException if numeric overflow occurs

    Parameters

    • multiplicand: number

      the value to multiply the duration by, positive or negative

    Returns Duration

  • 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

    Throws

    ArithmeticException if numeric overflow occurs

    Returns Duration

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

    This instance is immutable and unaffected by this method call.

    Returns

    a Duration based on this duration with the specified duration added

    Throws

    ArithmeticException if numeric overflow occurs

    Parameters

    • duration: Duration

      the duration to add, positive or negative

    Returns Duration

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

    Returns

    a Duration based on this duration with the specified days added.

    Throws

    ArithmeticException if numeric overflow occurs

    Parameters

    • daysToAdd: number

      the days to add, positive or negative

    Returns Duration

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

    This instance is immutable and unaffected by this method call.

    Returns

    a Duration based on this duration with the specified hours added

    Throws

    ArithmeticException if numeric overflow occurs

    Parameters

    • hoursToAdd: number

      the hours to add, positive or negative

    Returns Duration

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

    This instance is immutable and unaffected by this method call.

    Returns

    a Duration based on this duration with the specified milliseconds added

    Throws

    ArithmeticException if numeric overflow occurs

    Parameters

    • millisToAdd: number

      the milliseconds to add, positive or negative

    Returns Duration

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

    This instance is immutable and unaffected by this method call.

    Returns

    a Duration based on this duration with the specified minutes added

    Throws

    ArithmeticException if numeric overflow occurs

    Parameters

    • minutesToAdd: number

      the minutes to add, positive or negative

    Returns Duration

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

    This instance is immutable and unaffected by this method call.

    Returns

    a Duration based on this duration with the specified nanoseconds added

    Throws

    ArithmeticException if numeric overflow occurs

    Parameters

    • nanosToAdd: number

      the nanoseconds to add, positive or negative

    Returns Duration

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

    This instance is immutable and unaffected by this method call.

    Returns

    a Duration based on this duration with the specified seconds added

    Throws

    ArithmeticException if numeric overflow occurs

    Parameters

    • secondsToAdd: number

      the seconds to add, positive or negative

    Returns Duration

  • 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

    Returns number

  • Extracts the number of days in the 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

    Returns number

  • 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

    Returns number

  • Extracts the number of hours part in the duration.

    This returns the number of remaining hours when dividing [toHours] by hours in a day. 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 hours part in the duration, may be negative

    Returns number

  • 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 if numeric overflow occurs

    Returns number

  • Extracts the number of milliseconds part of the duration.

    This returns the milliseconds part by dividing the number of nanoseconds by 1,000,000. 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 [nano] and [seconds].

    This instance is immutable and unaffected by this method call.

    Returns

    the number of milliseconds part of the duration.

    Returns number

  • 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

    Returns number

  • Extracts the number of minutes part in the duration.

    This returns the number of remaining minutes when dividing [toMinutes] by minutes in an hour. This is based on the standard definition of an hour as 60 minutes.

    This instance is immutable and unaffected by this method call.

    Returns

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

    Returns number

  • 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 if numeric overflow occurs

    Returns number

  • Get the nanoseconds part within seconds of the 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 [nano] and [seconds].

    This instance is immutable and unaffected by this method call.

    Returns

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

    Returns number

  • Gets the number of seconds in this duration.

    This returns the total number of whole seconds in the duration.

    This instance is immutable and unaffected by this method call.

    Returns

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

    Returns number

  • Extracts the number of seconds part in the duration.

    This returns the remaining seconds when dividing [toSeconds] by seconds in a minute. This is based on the standard definition of a minute as 60 seconds.

    This instance is immutable and unaffected by this method call.

    Returns

    the number of seconds parts in the duration, may be negative

    Returns number

  • A string representation of this duration using ISO-8601 seconds based representation, such as PT8H6M12.345S.

    Returns

    an ISO-8601 representation of this duration.

    Returns string

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

    Returns

    a Duration based on this period with the requested nano-of-second.

    Throws

    DateTimeException if the nano-of-second is invalid

    Parameters

    • nanoOfSecond: number

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

    Returns Duration

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

    Returns

    a Duration based on this period with the requested seconds

    Parameters

    • seconds: number

      the seconds to represent, may be negative

    Returns Duration