Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Methods](https://developer.android.com/reference/java/time/chrono/ChronoPeriod#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/java/time/chrono/ChronoPeriod#inhmethods)

# ChronoPeriod

` public interface ChronoPeriod `   
` implements https://developer.android.com/reference/java/time/temporal/TemporalAmount `

|---|
| java.time.chrono.ChronoPeriod |

Known indirect subclasses [Period](https://developer.android.com/reference/java/time/Period) [Period](https://developer.android.com/reference/java/time/Period) A date-based amount of time in the ISO-8601 calendar system, such as '2 years, 3 months and 4 days'.   

*** ** * ** ***

A date-based amount of time, such as '3 years, 4 months and 5 days' in an arbitrary chronology, intended for advanced globalization use cases.

This interface models a date-based amount of time in a calendar system. While most calendar systems use years, months and days, some do not. Therefore, this interface operates solely in terms of a set of supported units that are defined by the `Chronology`. The set of supported units is fixed for a given chronology. The amount of a supported unit may be set to zero.

The period is modeled as a directed amount of time, meaning that individual parts of the period may be negative.

## Summary

| ### Public methods ||
|---|---|
| ` abstract https://developer.android.com/reference/java/time/temporal/Temporal` | ` https://developer.android.com/reference/java/time/chrono/ChronoPeriod#addTo(java.time.temporal.Temporal)(https://developer.android.com/reference/java/time/temporal/Temporal temporal) ` Adds this period to the specified temporal object. |
| ` static https://developer.android.com/reference/java/time/chrono/ChronoPeriod` | ` https://developer.android.com/reference/java/time/chrono/ChronoPeriod#between(java.time.chrono.ChronoLocalDate,%20java.time.chrono.ChronoLocalDate)(https://developer.android.com/reference/java/time/chrono/ChronoLocalDate startDateInclusive, https://developer.android.com/reference/java/time/chrono/ChronoLocalDate endDateExclusive) ` Obtains a `ChronoPeriod` consisting of amount of time between two dates. |
| ` abstract boolean` | ` https://developer.android.com/reference/java/time/chrono/ChronoPeriod#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) ` Checks if this period is equal to another period, including the chronology. |
| ` abstract long` | ` https://developer.android.com/reference/java/time/chrono/ChronoPeriod#get(java.time.temporal.TemporalUnit)(https://developer.android.com/reference/java/time/temporal/TemporalUnit unit) ` Gets the value of the requested unit. |
| ` abstract https://developer.android.com/reference/java/time/chrono/Chronology` | ` https://developer.android.com/reference/java/time/chrono/ChronoPeriod#getChronology()() ` Gets the chronology that defines the meaning of the supported units. |
| ` abstract https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/java/time/temporal/TemporalUnit>` | ` https://developer.android.com/reference/java/time/chrono/ChronoPeriod#getUnits()() ` Gets the set of units supported by this period. |
| ` abstract int` | ` https://developer.android.com/reference/java/time/chrono/ChronoPeriod#hashCode()() ` A hash code for this period. |
| ` default boolean` | ` https://developer.android.com/reference/java/time/chrono/ChronoPeriod#isNegative()() ` Checks if any of the supported units of this period are negative. |
| ` default boolean` | ` https://developer.android.com/reference/java/time/chrono/ChronoPeriod#isZero()() ` Checks if all the supported units of this period are zero. |
| ` abstract https://developer.android.com/reference/java/time/chrono/ChronoPeriod` | ` https://developer.android.com/reference/java/time/chrono/ChronoPeriod#minus(java.time.temporal.TemporalAmount)(https://developer.android.com/reference/java/time/temporal/TemporalAmount amountToSubtract) ` Returns a copy of this period with the specified period subtracted. |
| ` abstract https://developer.android.com/reference/java/time/chrono/ChronoPeriod` | ` https://developer.android.com/reference/java/time/chrono/ChronoPeriod#multipliedBy(int)(int scalar) ` Returns a new instance with each amount in this period in this period multiplied by the specified scalar. |
| ` default https://developer.android.com/reference/java/time/chrono/ChronoPeriod` | ` https://developer.android.com/reference/java/time/chrono/ChronoPeriod#negated()() ` Returns a new instance with each amount in this period negated. |
| ` abstract https://developer.android.com/reference/java/time/chrono/ChronoPeriod` | ` https://developer.android.com/reference/java/time/chrono/ChronoPeriod#normalized()() ` Returns a copy of this period with the amounts of each unit normalized. |
| ` abstract https://developer.android.com/reference/java/time/chrono/ChronoPeriod` | ` https://developer.android.com/reference/java/time/chrono/ChronoPeriod#plus(java.time.temporal.TemporalAmount)(https://developer.android.com/reference/java/time/temporal/TemporalAmount amountToAdd) ` Returns a copy of this period with the specified period added. |
| ` abstract https://developer.android.com/reference/java/time/temporal/Temporal` | ` https://developer.android.com/reference/java/time/chrono/ChronoPeriod#subtractFrom(java.time.temporal.Temporal)(https://developer.android.com/reference/java/time/temporal/Temporal temporal) ` Subtracts this period from the specified temporal object. |
| ` abstract https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/time/chrono/ChronoPeriod#toString()() ` Outputs this period as a `String`. |

### Inherited methods

From interface ` https://developer.android.com/reference/java/time/temporal/TemporalAmount ` ` abstract https://developer.android.com/reference/java/time/temporal/Temporal` ` https://developer.android.com/reference/java/time/temporal/TemporalAmount#addTo(java.time.temporal.Temporal)(https://developer.android.com/reference/java/time/temporal/Temporal temporal) `

Adds to the specified temporal object.
` abstract long` ` https://developer.android.com/reference/java/time/temporal/TemporalAmount#get(java.time.temporal.TemporalUnit)(https://developer.android.com/reference/java/time/temporal/TemporalUnit unit) `

Returns the value of the requested unit.
` abstract https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/java/time/temporal/TemporalUnit>` ` https://developer.android.com/reference/java/time/temporal/TemporalAmount#getUnits()() `

Returns the list of units uniquely defining the value of this TemporalAmount.
` abstract https://developer.android.com/reference/java/time/temporal/Temporal` ` https://developer.android.com/reference/java/time/temporal/TemporalAmount#subtractFrom(java.time.temporal.Temporal)(https://developer.android.com/reference/java/time/temporal/Temporal temporal) `

Subtracts this object from the specified temporal object.

## Public methods

### addTo

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract Temporal addTo (Temporal temporal)
```

Adds this period to the specified temporal object.

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

In most cases, it is clearer to reverse the calling pattern by using `https://developer.android.com/reference/java/time/temporal/Temporal#plus(java.time.temporal.TemporalAmount)`.

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

The specified temporal must have the same chronology as this period. This returns a temporal with the non-zero supported units added.

This instance is immutable and unaffected by this method call.

<br />

| Parameters ||
|---|---|
| `temporal` | `Temporal`: the temporal object to adjust, not null <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/time/temporal/Temporal` | an object of the same type with the adjustment made, not null <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/ArithmeticException` | if numeric overflow occurs |
| `https://developer.android.com/reference/java/time/DateTimeException` | if unable to add |

### between

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static ChronoPeriod between (ChronoLocalDate startDateInclusive, 
                ChronoLocalDate endDateExclusive)
```

Obtains a `ChronoPeriod` consisting of amount of time between two dates.

The start date is included, but the end date is not. The period is calculated using `https://developer.android.com/reference/java/time/chrono/ChronoLocalDate#until(java.time.chrono.ChronoLocalDate)`. As such, the calculation is chronology specific.

The chronology of the first date is used. The chronology of the second date is ignored, with the date being converted to the target chronology system before the calculation starts.

The result of this method can be a negative period if the end is before the start. In most cases, the positive/negative sign will be the same in each of the supported fields.

<br />

| Parameters ||
|---|---|
| `startDateInclusive` | `ChronoLocalDate`: the start date, inclusive, specifying the chronology of the calculation, not null <br /> |
| `endDateExclusive` | `ChronoLocalDate`: the end date, exclusive, in any chronology, not null <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/time/chrono/ChronoPeriod` | the period between this date and the end date, not null <br /> |

**See also:**

- `https://developer.android.com/reference/java/time/chrono/ChronoLocalDate#until(java.time.chrono.ChronoLocalDate)`

### equals

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract boolean equals (Object obj)
```

Checks if this period is equal to another period, including the chronology.

Compares this period with another ensuring that the type, each amount and the chronology are the same. Note that this means that a period of "15 Months" is not equal to a period of "1 Year and 3 Months".

<br />

| Parameters ||
|---|---|
| `obj` | `Object`: the object to check, null returns false <br /> |

| Returns ||
|---|---|
| `boolean` | true if this is equal to the other period <br /> |

### get

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract long get (TemporalUnit unit)
```

Gets the value of the requested unit.

The supported units are chronology specific. They will typically be `https://developer.android.com/reference/java/time/temporal/ChronoUnit#YEARS`, `https://developer.android.com/reference/java/time/temporal/ChronoUnit#MONTHS` and `https://developer.android.com/reference/java/time/temporal/ChronoUnit#DAYS`. Requesting an unsupported unit will throw an exception.

<br />

| Parameters ||
|---|---|
| `unit` | `TemporalUnit`: the `TemporalUnit` for which to return the value <br /> |

| Returns ||
|---|---|
| `long` | the long value of the unit <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/time/DateTimeException` | if the unit is not supported |
| `https://developer.android.com/reference/java/time/temporal/UnsupportedTemporalTypeException` | if the unit is not supported |

### getChronology

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract Chronology getChronology ()
```

Gets the chronology that defines the meaning of the supported units.

The period is defined by the chronology. It controls the supported units and restricts addition/subtraction to `ChronoLocalDate` instances of the same chronology.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/time/chrono/Chronology` | the chronology defining the period, not null <br /> |

### getUnits

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract List<TemporalUnit> getUnits ()
```

Gets the set of units supported by this period.

The supported units are chronology specific. They will typically be `https://developer.android.com/reference/java/time/temporal/ChronoUnit#YEARS`, `https://developer.android.com/reference/java/time/temporal/ChronoUnit#MONTHS` and `https://developer.android.com/reference/java/time/temporal/ChronoUnit#DAYS`. They are returned in order from largest to smallest.

This set can be used in conjunction with `https://developer.android.com/reference/java/time/chrono/ChronoPeriod#get(java.time.temporal.TemporalUnit)` to access the entire state of the period.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/java/time/temporal/TemporalUnit>` | a list containing the supported units, not null <br /> |

### hashCode

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract int hashCode ()
```

A hash code for this period.

<br />

| Returns ||
|---|---|
| `int` | a suitable hash code <br /> |

### isNegative

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean isNegative ()
```

Checks if any of the supported units of this period are negative.

<br />

| Returns ||
|---|---|
| `boolean` | true if any unit of this period is negative <br /> |

### isZero

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean isZero ()
```

Checks if all the supported units of this period are zero.

<br />

| Returns ||
|---|---|
| `boolean` | true if this period is zero-length <br /> |

### minus

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract ChronoPeriod minus (TemporalAmount amountToSubtract)
```

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

If the specified amount is a `ChronoPeriod` then it must have the same chronology as this period. Implementations may choose to accept or reject other `TemporalAmount` implementations.

This instance is immutable and unaffected by this method call.

<br />

| Parameters ||
|---|---|
| `amountToSubtract` | `TemporalAmount`: the period to subtract, not null <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/time/chrono/ChronoPeriod` | a `ChronoPeriod` based on this period with the requested period subtracted, not null <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/ArithmeticException` | if numeric overflow occurs |

### multipliedBy

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract ChronoPeriod multipliedBy (int scalar)
```

Returns a new instance with each amount in this period in this period multiplied by the specified scalar.

This returns a period with each supported unit individually multiplied. For example, a period of "2 years, -3 months and 4 days" multiplied by 3 will return "6 years, -9 months and 12 days". No normalization is performed.

<br />

| Parameters ||
|---|---|
| `scalar` | `int`: the scalar to multiply by, not null <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/time/chrono/ChronoPeriod` | a `ChronoPeriod` based on this period with the amounts multiplied by the scalar, not null <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/ArithmeticException` | if numeric overflow occurs |

### negated

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public ChronoPeriod negated ()
```

Returns a new instance with each amount in this period negated.

This returns a period with each supported unit individually negated. For example, a period of "2 years, -3 months and 4 days" will be negated to "-2 years, 3 months and -4 days". No normalization is performed.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/time/chrono/ChronoPeriod` | a `ChronoPeriod` based on this period with the amounts negated, not null <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/ArithmeticException` | if numeric overflow occurs, which only happens if one of the units has the value `Long.MIN_VALUE` |

### normalized

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract ChronoPeriod normalized ()
```

Returns a copy of this period with the amounts of each unit normalized.

The process of normalization is specific to each calendar system. For example, in the ISO calendar system, the years and months are normalized but the days are not, such that "15 months" would be normalized to "1 year and 3 months".

This instance is immutable and unaffected by this method call.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/time/chrono/ChronoPeriod` | a `ChronoPeriod` based on this period with the amounts of each unit normalized, not null <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/ArithmeticException` | if numeric overflow occurs |

### plus

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract ChronoPeriod plus (TemporalAmount amountToAdd)
```

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

If the specified amount is a `ChronoPeriod` then it must have the same chronology as this period. Implementations may choose to accept or reject other `TemporalAmount` implementations.

This instance is immutable and unaffected by this method call.

<br />

| Parameters ||
|---|---|
| `amountToAdd` | `TemporalAmount`: the period to add, not null <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/time/chrono/ChronoPeriod` | a `ChronoPeriod` based on this period with the requested period added, not null <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/ArithmeticException` | if numeric overflow occurs |

### subtractFrom

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract Temporal subtractFrom (Temporal temporal)
```

Subtracts this period from the specified temporal object.

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

In most cases, it is clearer to reverse the calling pattern by using `https://developer.android.com/reference/java/time/temporal/Temporal#minus(java.time.temporal.TemporalAmount)`.

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

The specified temporal must have the same chronology as this period. This returns a temporal with the non-zero supported units subtracted.

This instance is immutable and unaffected by this method call.

<br />

| Parameters ||
|---|---|
| `temporal` | `Temporal`: the temporal object to adjust, not null <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/time/temporal/Temporal` | an object of the same type with the adjustment made, not null <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/ArithmeticException` | if numeric overflow occurs |
| `https://developer.android.com/reference/java/time/DateTimeException` | if unable to subtract |

### toString

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract String toString ()
```

Outputs this period as a `String`.

The output will include the period amounts and chronology.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | a string representation of this period, not null <br /> |