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
Locale | Localized value |
---|---|
en-US | 18 minutes ago |
fr-FR | il y a 18 minutes |
de-DE | vor 18 Minuten |
fi-FI | 18 minuuttia sitten |
sv-FI | för 18 minuter sedan |
ko-KR | 18분 전 |
hi-IN | 18 मिनट पहले |