Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Nested Classes](https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter#nestedclasses) \| [Methods](https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter#inhmethods)

# RelativeDateTimeFormatter

*** ** * ** ***

` public final class RelativeDateTimeFormatter `   
` extends https://developer.android.com/reference/java/lang/Object ` ` `

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.icu.text.RelativeDateTimeFormatter |

<br />

*** ** * ** ***

Formats simple relative dates. There are two types of relative dates that it handles:

- relative dates with a quantity e.g "in 5 days"
- relative dates without a quantity e.g "next Tuesday"

This API is very basic and is intended to be a building block for more fancy APIs. The caller tells it exactly what to display in a locale independent way. While this class automatically provides the correct plural forms, the grammatical form is otherwise as neutral as possible. It is the caller's responsibility to handle cut-off logic such as deciding between displaying "in 7 days" or "in 1 week." This API supports relative dates involving one single unit. This API does not support relative dates involving compound units. e.g "in 5 days and 4 hours" nor does it support parsing. This class is both immutable and thread-safe.

Here are some examples of use:
>
> ```
> RelativeDateTimeFormatter fmt = RelativeDateTimeFormatter.getInstance();
> fmt.format(1, Direction.NEXT, RelativeUnit.DAYS); // "in 1 day"
> fmt.format(3, Direction.NEXT, RelativeUnit.DAYS); // "in 3 days"
> fmt.format(3.2, Direction.LAST, RelativeUnit.YEARS); // "3.2 years ago"
>
> fmt.format(Direction.LAST, AbsoluteUnit.SUNDAY); // "last Sunday"
> fmt.format(Direction.THIS, AbsoluteUnit.SUNDAY); // "this Sunday"
> fmt.format(Direction.NEXT, AbsoluteUnit.SUNDAY); // "next Sunday"
> fmt.format(Direction.PLAIN, AbsoluteUnit.SUNDAY); // "Sunday"
>
> fmt.format(Direction.LAST, AbsoluteUnit.DAY); // "yesterday"
> fmt.format(Direction.THIS, AbsoluteUnit.DAY); // "today"
> fmt.format(Direction.NEXT, AbsoluteUnit.DAY); // "tomorrow"
>
> fmt.format(Direction.PLAIN, AbsoluteUnit.NOW); // "now"
> ```

The Style parameter allows selection of different length styles: LONG ("3 seconds ago"), SHORT ("3 sec. ago"), NARROW ("3s ago"). In the future, we may add more forms, such as relative day periods ("yesterday afternoon"), etc.

## Summary

| ### Nested classes ||
|---|---|
| ` class` | `https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter.FormattedRelativeDateTime` Represents the result of a formatting operation of a relative datetime. |

| ### Public methods ||
|---|---|
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter#combineDateAndTime(java.lang.String,%20java.lang.String)(https://developer.android.com/reference/java/lang/String relativeDateString, https://developer.android.com/reference/java/lang/String timeString) ` Combines a relative date string and a time string in this object's locale. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter#format(double,%20android.icu.text.RelativeDateTimeFormatter.Direction,%20android.icu.text.RelativeDateTimeFormatter.RelativeUnit)(double quantity, https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter.Direction direction, https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter.RelativeUnit unit) ` Formats a relative date with a quantity such as "in 5 days" or "3 months ago". |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter#format(android.icu.text.RelativeDateTimeFormatter.Direction,%20android.icu.text.RelativeDateTimeFormatter.AbsoluteUnit)(https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter.Direction direction, https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter.AbsoluteUnit unit) ` Formats a relative date without a quantity. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter#format(double,%20android.icu.text.RelativeDateTimeFormatter.RelativeDateTimeUnit)(double offset, https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter.RelativeDateTimeUnit unit) ` Format a combination of RelativeDateTimeUnit and numeric offset using a text style if possible, e.g. "last week", "this week", "next week", "yesterday", "tomorrow". |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter#formatNumeric(double,%20android.icu.text.RelativeDateTimeFormatter.RelativeDateTimeUnit)(double offset, https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter.RelativeDateTimeUnit unit) ` Format a combination of RelativeDateTimeUnit and numeric offset using a numeric style, e.g. "1 week ago", "in 1 week", "5 weeks ago", "in 5 weeks". |
| ` https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter.FormattedRelativeDateTime` | ` https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter#formatNumericToValue(double,%20android.icu.text.RelativeDateTimeFormatter.RelativeDateTimeUnit)(double offset, https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter.RelativeDateTimeUnit unit) ` Format a combination of RelativeDateTimeUnit and numeric offset using a numeric style, e.g. "1 week ago", "in 1 week", "5 weeks ago", "in 5 weeks". |
| ` https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter.FormattedRelativeDateTime` | ` https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter#formatToValue(double,%20android.icu.text.RelativeDateTimeFormatter.Direction,%20android.icu.text.RelativeDateTimeFormatter.RelativeUnit)(double quantity, https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter.Direction direction, https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter.RelativeUnit unit) ` Formats a relative date with a quantity such as "in 5 days" or "3 months ago". |
| ` https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter.FormattedRelativeDateTime` | ` https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter#formatToValue(double,%20android.icu.text.RelativeDateTimeFormatter.RelativeDateTimeUnit)(double offset, https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter.RelativeDateTimeUnit unit) ` Format a combination of RelativeDateTimeUnit and numeric offset using a text style if possible, e.g. "last week", "this week", "next week", "yesterday", "tomorrow". |
| ` https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter.FormattedRelativeDateTime` | ` https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter#formatToValue(android.icu.text.RelativeDateTimeFormatter.Direction,%20android.icu.text.RelativeDateTimeFormatter.AbsoluteUnit)(https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter.Direction direction, https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter.AbsoluteUnit unit) ` Formats a relative date without a quantity. |
| ` https://developer.android.com/reference/android/icu/text/DisplayContext` | ` https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter#getCapitalizationContext()() ` Return capitalization context. |
| ` https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter.Style` | ` https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter#getFormatStyle()() ` Return style |
| ` static https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter` | ` https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter#getInstance(android.icu.util.ULocale,%20android.icu.text.NumberFormat,%20android.icu.text.RelativeDateTimeFormatter.Style,%20android.icu.text.DisplayContext)(https://developer.android.com/reference/android/icu/util/ULocale locale, https://developer.android.com/reference/android/icu/text/NumberFormat nf, https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter.Style style, https://developer.android.com/reference/android/icu/text/DisplayContext capitalizationContext) ` Returns a RelativeDateTimeFormatter for a particular locale that uses a particular NumberFormat object, style, and capitalization context |
| ` static https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter` | ` https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter#getInstance(android.icu.util.ULocale)(https://developer.android.com/reference/android/icu/util/ULocale locale) ` Returns a RelativeDateTimeFormatter for a particular locale. |
| ` static https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter` | ` https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter#getInstance()() ` Returns a RelativeDateTimeFormatter for the default locale. |
| ` static https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter` | ` https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter#getInstance(android.icu.util.ULocale,%20android.icu.text.NumberFormat)(https://developer.android.com/reference/android/icu/util/ULocale locale, https://developer.android.com/reference/android/icu/text/NumberFormat nf) ` Returns a RelativeDateTimeFormatter for a particular locale that uses a particular NumberFormat object. |
| ` static https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter` | ` https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter#getInstance(java.util.Locale)(https://developer.android.com/reference/java/util/Locale locale) ` Returns a RelativeDateTimeFormatter for a particular `https://developer.android.com/reference/java/util/Locale`. |
| ` static https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter` | ` https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter#getInstance(java.util.Locale,%20android.icu.text.NumberFormat)(https://developer.android.com/reference/java/util/Locale locale, https://developer.android.com/reference/android/icu/text/NumberFormat nf) ` Returns a RelativeDateTimeFormatter for a particular `https://developer.android.com/reference/java/util/Locale` that uses a particular NumberFormat object. |
| ` https://developer.android.com/reference/android/icu/text/NumberFormat` | ` https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter#getNumberFormat()() ` Returns a copy of the NumberFormat this object is using. |

### Inherited methods

From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` https://developer.android.com/reference/java/lang/Object#finalize()() `

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
` final https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait()() `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*.

## Public methods

### combineDateAndTime

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

```
public String combineDateAndTime (String relativeDateString, 
                String timeString)
```

Combines a relative date string and a time string in this object's locale. This is done with the same date-time separator used for the default calendar in this locale.

<br />

| Parameters ||
|---|---|
| `relativeDateString` | `String`: the relative date e.g 'yesterday' <br /> |
| `timeString` | `String`: the time e.g '3:45' <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | the date and time concatenated according to the default calendar in this locale e.g 'yesterday, 3:45' <br /> |

### format

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

```
public String format (double quantity, 
                RelativeDateTimeFormatter.Direction direction, 
                RelativeDateTimeFormatter.RelativeUnit unit)
```

Formats a relative date with a quantity such as "in 5 days" or "3 months ago". This method returns a String. To get more information about the formatting result, use formatToValue().

<br />

| Parameters ||
|---|---|
| `quantity` | `double`: The numerical amount e.g 5. This value is formatted according to this object's `https://developer.android.com/reference/android/icu/text/NumberFormat` object. <br /> |
| `direction` | `RelativeDateTimeFormatter.Direction`: NEXT means a future relative date; LAST means a past relative date. <br /> |
| `unit` | `RelativeDateTimeFormatter.RelativeUnit`: the unit e.g day? month? year? <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | the formatted string <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if direction is something other than NEXT or LAST. |

### format

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

```
public String format (RelativeDateTimeFormatter.Direction direction, 
                RelativeDateTimeFormatter.AbsoluteUnit unit)
```

Formats a relative date without a quantity. This method returns a String. To get more information about the formatting result, use formatToValue().

<br />

| Parameters ||
|---|---|
| `direction` | `RelativeDateTimeFormatter.Direction`: NEXT, LAST, THIS, etc. <br /> |
| `unit` | `RelativeDateTimeFormatter.AbsoluteUnit`: e.g SATURDAY, DAY, MONTH <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | the formatted string. If direction has a value that is documented as not being fully supported in every locale (for example NEXT_2 or LAST_2) then this function may return null to signal that no formatted string is available. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if the direction is incompatible with unit this can occur with NOW which can only take PLAIN. |

### format

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

```
public String format (double offset, 
                RelativeDateTimeFormatter.RelativeDateTimeUnit unit)
```

Format a combination of RelativeDateTimeUnit and numeric offset using a text style if possible, e.g. "last week", "this week", "next week", "yesterday", "tomorrow". Falls back to numeric style if no appropriate text term is available for the specified offset in the object\\u2019s locale. This method returns a String. To get more information about the formatting result, use formatToValue().

<br />

| Parameters ||
|---|---|
| `offset` | `double`: The signed offset for the specified field. <br /> |
| `unit` | `RelativeDateTimeFormatter.RelativeDateTimeUnit`: The unit to use when formatting the relative date, e.g. RelativeDateTimeUnit.WEEK, RelativeDateTimeUnit.FRIDAY. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | The formatted string (may be empty in case of error) <br /> |

### formatNumeric

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

```
public String formatNumeric (double offset, 
                RelativeDateTimeFormatter.RelativeDateTimeUnit unit)
```

Format a combination of RelativeDateTimeUnit and numeric offset using a numeric style, e.g. "1 week ago", "in 1 week", "5 weeks ago", "in 5 weeks". This method returns a String. To get more information about the formatting result, use formatNumericToValue().

<br />

| Parameters ||
|---|---|
| `offset` | `double`: The signed offset for the specified unit. This will be formatted according to this object's NumberFormat object. <br /> |
| `unit` | `RelativeDateTimeFormatter.RelativeDateTimeUnit`: The unit to use when formatting the relative date, e.g. RelativeDateTimeUnit.WEEK, RelativeDateTimeUnit.FRIDAY. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | The formatted string (may be empty in case of error) <br /> |

### formatNumericToValue

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

```
public RelativeDateTimeFormatter.FormattedRelativeDateTime formatNumericToValue (double offset, 
                RelativeDateTimeFormatter.RelativeDateTimeUnit unit)
```

Format a combination of RelativeDateTimeUnit and numeric offset using a numeric style, e.g. "1 week ago", "in 1 week", "5 weeks ago", "in 5 weeks". This method returns a FormattedRelativeDateTime, which exposes more information than the String returned by formatNumeric().

<br />

| Parameters ||
|---|---|
| `offset` | `double`: The signed offset for the specified unit. This will be formatted according to this object's NumberFormat object. <br /> |
| `unit` | `RelativeDateTimeFormatter.RelativeDateTimeUnit`: The unit to use when formatting the relative date, e.g. RelativeDateTimeUnit.WEEK, RelativeDateTimeUnit.FRIDAY. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter.FormattedRelativeDateTime` | The formatted string (may be empty in case of error) <br /> |

### formatToValue

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

```
public RelativeDateTimeFormatter.FormattedRelativeDateTime formatToValue (double quantity, 
                RelativeDateTimeFormatter.Direction direction, 
                RelativeDateTimeFormatter.RelativeUnit unit)
```

Formats a relative date with a quantity such as "in 5 days" or "3 months ago". This method returns a FormattedRelativeDateTime, which exposes more information than the String returned by format().

<br />

| Parameters ||
|---|---|
| `quantity` | `double`: The numerical amount e.g 5. This value is formatted according to this object's `https://developer.android.com/reference/android/icu/text/NumberFormat` object. <br /> |
| `direction` | `RelativeDateTimeFormatter.Direction`: NEXT means a future relative date; LAST means a past relative date. <br /> |
| `unit` | `RelativeDateTimeFormatter.RelativeUnit`: the unit e.g day? month? year? <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter.FormattedRelativeDateTime` | the formatted relative datetime <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if direction is something other than NEXT or LAST. |

### formatToValue

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

```
public RelativeDateTimeFormatter.FormattedRelativeDateTime formatToValue (double offset, 
                RelativeDateTimeFormatter.RelativeDateTimeUnit unit)
```

Format a combination of RelativeDateTimeUnit and numeric offset using a text style if possible, e.g. "last week", "this week", "next week", "yesterday", "tomorrow". Falls back to numeric style if no appropriate text term is available for the specified offset in the object\\u2019s locale. This method returns a FormattedRelativeDateTime, which exposes more information than the String returned by format().

<br />

| Parameters ||
|---|---|
| `offset` | `double`: The signed offset for the specified field. <br /> |
| `unit` | `RelativeDateTimeFormatter.RelativeDateTimeUnit`: The unit to use when formatting the relative date, e.g. RelativeDateTimeUnit.WEEK, RelativeDateTimeUnit.FRIDAY. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter.FormattedRelativeDateTime` | The formatted string (may be empty in case of error) <br /> |

### formatToValue

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

```
public RelativeDateTimeFormatter.FormattedRelativeDateTime formatToValue (RelativeDateTimeFormatter.Direction direction, 
                RelativeDateTimeFormatter.AbsoluteUnit unit)
```

Formats a relative date without a quantity. This method returns a FormattedRelativeDateTime, which exposes more information than the String returned by format().

<br />

| Parameters ||
|---|---|
| `direction` | `RelativeDateTimeFormatter.Direction`: NEXT, LAST, THIS, etc. <br /> |
| `unit` | `RelativeDateTimeFormatter.AbsoluteUnit`: e.g SATURDAY, DAY, MONTH <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter.FormattedRelativeDateTime` | the formatted string. If direction has a value that is documented as not being fully supported in every locale (for example NEXT_2 or LAST_2) then this function may return null to signal that no formatted string is available. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if the direction is incompatible with unit this can occur with NOW which can only take PLAIN. |

### getCapitalizationContext

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

```
public DisplayContext getCapitalizationContext ()
```

Return capitalization context.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/icu/text/DisplayContext` | The capitalization context. <br /> |

### getFormatStyle

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

```
public RelativeDateTimeFormatter.Style getFormatStyle ()
```

Return style

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter.Style` | The formatting style. <br /> |

### getInstance

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

```
public static RelativeDateTimeFormatter getInstance (ULocale locale, 
                NumberFormat nf, 
                RelativeDateTimeFormatter.Style style, 
                DisplayContext capitalizationContext)
```

Returns a RelativeDateTimeFormatter for a particular locale that uses a particular NumberFormat object, style, and capitalization context

<br />

| Parameters ||
|---|---|
| `locale` | `ULocale`: the locale <br /> |
| `nf` | `NumberFormat`: the number format object. It is defensively copied to ensure thread-safety and immutability of this class. May be null. <br /> |
| `style` | `RelativeDateTimeFormatter.Style`: the style. <br /> |
| `capitalizationContext` | `DisplayContext`: the capitalization context. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter` | <br /> |

### getInstance

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

```
public static RelativeDateTimeFormatter getInstance (ULocale locale)
```

Returns a RelativeDateTimeFormatter for a particular locale.

<br />

| Parameters ||
|---|---|
| `locale` | `ULocale`: the locale. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter` | An instance of RelativeDateTimeFormatter. <br /> |

### getInstance

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

```
public static RelativeDateTimeFormatter getInstance ()
```

Returns a RelativeDateTimeFormatter for the default locale.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter` | <br /> |

### getInstance

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

```
public static RelativeDateTimeFormatter getInstance (ULocale locale, 
                NumberFormat nf)
```

Returns a RelativeDateTimeFormatter for a particular locale that uses a particular NumberFormat object.

<br />

| Parameters ||
|---|---|
| `locale` | `ULocale`: the locale <br /> |
| `nf` | `NumberFormat`: the number format object. It is defensively copied to ensure thread-safety and immutability of this class. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter` | An instance of RelativeDateTimeFormatter. <br /> |

### getInstance

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

```
public static RelativeDateTimeFormatter getInstance (Locale locale)
```

Returns a RelativeDateTimeFormatter for a particular `https://developer.android.com/reference/java/util/Locale`.

<br />

| Parameters ||
|---|---|
| `locale` | `Locale`: the `https://developer.android.com/reference/java/util/Locale`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter` | An instance of RelativeDateTimeFormatter. <br /> |

### getInstance

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

```
public static RelativeDateTimeFormatter getInstance (Locale locale, 
                NumberFormat nf)
```

Returns a RelativeDateTimeFormatter for a particular `https://developer.android.com/reference/java/util/Locale` that uses a particular NumberFormat object.

<br />

| Parameters ||
|---|---|
| `locale` | `Locale`: the `https://developer.android.com/reference/java/util/Locale` <br /> |
| `nf` | `NumberFormat`: the number format object. It is defensively copied to ensure thread-safety and immutability of this class. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/icu/text/RelativeDateTimeFormatter` | An instance of RelativeDateTimeFormatter. <br /> |

### getNumberFormat

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

```
public NumberFormat getNumberFormat ()
```

Returns a copy of the NumberFormat this object is using.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/icu/text/NumberFormat` | A copy of the NumberFormat. <br /> |