Skip to content

relativeTimeFormatter
@localizer/format-datetime 1.1.1

The relativeTimeFormatter provides a flexible way to format relative time expressions, allowing you to describe moments in the past or future with ease. It supports customizable options to tailor the output to your specific needs, such as numeric representation and stop points for granularity.

Usage

typescript
import { 
relativeTimeFormatter
} from '@localizer/format-relativetime';
const
formatter
=
relativeTimeFormatter
({
numeric
: 'auto',
stops
: ['day'] });
const
reference
= new
Date
(2025, 2, 23, 12, 59, 0); // Typically new Date()
const
value
= new
Date
(2025, 2, 23, 11, 40, 35);
const
result
=
formatter
(
reference
,
value
);

See formatter options for configuration details.

Demo

─── unset ───
auto
day
LocaleLocalized value
en-US  American English18 minutes ago
fr-FR  French (France)il y a 18 minutes
de-DE  German (Germany)vor 18 Minuten
fi-FI  Finnish (Finland)18 minuuttia sitten
sv-FI  Swedish (Finland)för 18 minuter sedan
ko-KR  Korean (South Korea)18분 전
hi-IN  Hindi (India)18 मिनट पहले

See also