---
title: RelativeDateTimeFormatter
description: Creates a textual representation of the amount of time between two dates.
---

Creates a textual representation of the amount of time between two dates.

The relative date formatter takes two dates as input and creates a textual representation that communicates the relative time between the two dates, e.g. "yesterday" and "in 1 week".

## Properties

### locale

Locale to use when formatting.

```typescript
locale: string
```

The locale should be specified using a string identifier, e.g. "en", "it" or "da". When no locale is set, the formatter will use the current locale of the device.

## Methods

<span id="-new-relativedatetimeformatter" class="api-anchor"></span>

### new RelativeDateTimeFormatter()

Constructs a relative date and time formatter.

```typescript
new RelativeDateTimeFormatter()
```

The formatter creates a textual representation of the time between two points in time.

<span id="-string" class="api-anchor"></span>

### string(date, referenceDate)

Creates a localized string communicating the amount of time between two dates.

```typescript
string(date: Date, referenceDate: Date): string
```

Creates a localized textual representation of the amount of time between to dates. If the two dates are the same, the function will return "now". If the reference date is yesterday, the function will return "yesterday". Other examples include "in 10 seconds", "2 hours ago", "last week" and "next year".

#### Parameters

**`date` `Date`**

The date to create a relative date and time for.

**`referenceDate` `Date`**

The reference date that `date` is relative to.

#### Return value

**`string`**

A textual representation of the amount of time between the two dates.

<span id="-usenameddatetimestyle" class="api-anchor"></span>

### useNamedDateTimeStyle()

Prefers named dates and times.

```typescript
useNamedDateTimeStyle()
```

When using the named style, the formatter tries to find a suitable textual representation over a numeric value for the relative time, e.g. "now" instead of "in 0 seconds" and "yesterday" instead of "1 day ago".

When no named representation is found the formatter will fallback to using the numeric style.

<span id="-usenumericdatetimestyle" class="api-anchor"></span>

### useNumericDateTimeStyle()

Prefers numeric dates and times.

```typescript
useNumericDateTimeStyle()
```

When using the numeric style, the formatter will always prefer numeric representations over named representations. E.g. it will return "in 0 seconds" instead of "now" and "1 day ago" instead of "yesteday".