Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.joda.time
Class Duration

    java.lang.Object
      org.joda.time.base.AbstractDuration
          org.joda.time.base.BaseDuration
              org.joda.time.Duration

All Implemented Interfaces:
  java.io.Serializable, java.lang.Comparable, ReadableDuration

    public final class Duration

extends BaseDuration
implements ReadableDuration, java.io.Serializable

An immutable duration specifying a length of time in milliseconds.

A duration is defined by a fixed number of milliseconds. There is no concept of fields, such as days or seconds, as these fields can vary in length. A duration may be converted to a `Period` to obtain field values. This conversion will typically cause a loss of precision however.

Duration is thread-safe and immutable.

Since:
  1.0
Author:
  Brian S O'Neill, Stephen Colebourne
See Also:
  Serialized Form

Field Summary
`static Duration` | `ZERO` Constant representing zero millisecond duration

Constructor Summary
`Duration(long duration)` Creates a duration from the given millisecond duration.
`Duration(long startInstant, long endInstant)` Creates a duration from the given interval endpoints.
`Duration(java.lang.Object duration)` Creates a duration from the specified object using the `ConverterManager`.
`Duration(ReadableInstant start, ReadableInstant end)` Creates a duration from the given interval endpoints.

Method Summary
`Duration` | `minus(long amount)` Returns a new duration with this length minus that specified.
`Duration` | `minus(ReadableDuration amount)` Returns a new duration with this length minus that specified.
`Duration` | `plus(long amount)` Returns a new duration with this length plus that specified.
`Duration` | `plus(ReadableDuration amount)` Returns a new duration with this length plus that specified.
`Duration` | `toDuration()` Get this duration as an immutable `Duration` object by returning `this`.
`Duration` | `withDurationAdded(long durationToAdd, int scalar)` Returns a new duration with this length plus that specified multiplied by the scalar.
`Duration` | `withDurationAdded(ReadableDuration durationToAdd, int scalar)` Returns a new duration with this length plus that specified multiplied by the scalar.
`Duration` | `withMillis(long duration)` Creates a new Duration instance with a different milisecond length.

Methods inherited from class org.joda.time.base.BaseDuration
`getMillis, setMillis, toIntervalFrom, toIntervalTo, toPeriod, toPeriod, toPeriod, toPeriodFrom, toPeriodFrom, toPeriodTo, toPeriodTo`

Methods inherited from class org.joda.time.base.AbstractDuration
`compareTo, equals, hashCode, isEqual, isLongerThan, isShorterThan, toPeriod, toString`

Methods inherited from class java.lang.Object
`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

Methods inherited from interface org.joda.time.ReadableDuration
`compareTo, equals, getMillis, hashCode, isEqual, isLongerThan, isShorterThan, toPeriod, toString`

Field Detail

### ZERO

    public static final Duration ZERO

  Constant representing zero millisecond duration

Constructor Detail

### Duration

    public Duration(long duration)

  Creates a duration from the given millisecond duration.

  Parameters:
    `duration` - the duration, in milliseconds

### Duration

    public Duration(long startInstant,
                    long endInstant)

  Creates a duration from the given interval endpoints.

  Parameters:
    `startInstant` - interval start, in milliseconds
    `endInstant` - interval end, in milliseconds
  Throws:
    `java.lang.ArithmeticException` - if the duration exceeds a 64 bit long

### Duration

    public Duration(ReadableInstant start,
                    ReadableInstant end)

  Creates a duration from the given interval endpoints.

  Parameters:
    `start` - interval start, null means now
    `end` - interval end, null means now
  Throws:
    `java.lang.ArithmeticException` - if the duration exceeds a 64 bit long

### Duration

    public Duration(java.lang.Object duration)

  Creates a duration from the specified object using the `ConverterManager`.

  Parameters:
    `duration` - duration to convert
  Throws:
    `java.lang.IllegalArgumentException` - if duration is invalid

Method Detail

### toDuration

    public Duration toDuration()

  Get this duration as an immutable `Duration` object by returning `this`.

  Specified by:
    `toDuration` in interface `ReadableDuration`
  Overrides:
    `toDuration` in class `AbstractDuration`
  Returns:
    `this`

### withMillis

    public Duration withMillis(long duration)

  Creates a new Duration instance with a different milisecond length.

  Parameters:
    `duration` - the new length of the duration
  Returns:
    the new duration instance

### withDurationAdded

    public Duration withDurationAdded(long durationToAdd,
                                      int scalar)

  Returns a new duration with this length plus that specified multiplied by the scalar. This instance is immutable and is not altered.

  If the addition is zero, this instance is returned.

  Parameters:
    `durationToAdd` - the duration to add to this one
    `scalar` - the amount of times to add, such as -1 to subtract once
  Returns:
    the new duration instance

### withDurationAdded

    public Duration withDurationAdded(ReadableDuration durationToAdd,
                                      int scalar)

  Returns a new duration with this length plus that specified multiplied by the scalar. This instance is immutable and is not altered.

  If the addition is zero, this instance is returned.

  Parameters:
    `durationToAdd` - the duration to add to this one, null means zero
    `scalar` - the amount of times to add, such as -1 to subtract once
  Returns:
    the new duration instance

### plus

    public Duration plus(long amount)

  Returns a new duration with this length plus that specified. This instance is immutable and is not altered.

  If the addition is zero, this instance is returned.

  Parameters:
    `amount` - the duration to add to this one
  Returns:
    the new duration instance

### plus

    public Duration plus(ReadableDuration amount)

  Returns a new duration with this length plus that specified. This instance is immutable and is not altered.

  If the amount is zero, this instance is returned.

  Parameters:
    `amount` - the duration to add to this one, null means zero
  Returns:
    the new duration instance

### minus

    public Duration minus(long amount)

  Returns a new duration with this length minus that specified. This instance is immutable and is not altered.

  If the addition is zero, this instance is returned.

  Parameters:
    `amount` - the duration to take away from this one
  Returns:
    the new duration instance

### minus

    public Duration minus(ReadableDuration amount)

  Returns a new duration with this length minus that specified. This instance is immutable and is not altered.

  If the amount is zero, this instance is returned.

  Parameters:
    `amount` - the duration to take away from this one, null means zero
  Returns:
    the new duration instance

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD