-
Couldn't load subscription status.
- Fork 4
Function.formatRelativeTime
connor-baer edited this page Mar 28, 2025
·
22 revisions
@sumup-oss/intl / formatRelativeTime
formatRelativeTime(
value,unit,locales?,options?):string
Defined in: lib/relative-time-format/index.ts:44
Formats a relative time with support for various styles.
| Parameter | Type |
|---|---|
value |
number |
unit |
RelativeTimeFormatUnit |
locales? |
string | string[] |
options? |
RelativeTimeFormatOptions |
string
import { formatRelativeTime } from '@sumup-oss/intl';
formatRelativeTime(1, 'day', 'de-DE'); // 'in 1 Tag'
formatRelativeTime(7, 'years', ['pt-BR', 'pt']); // 'em 7 anos'
formatRelativeTime(-5, 'months', 'en-GB', {
style: 'narrow',
}); // '5 mo ago'In runtimes that don't support the Intl.RelativeTimeFormat API,
the relative time is formatted using the Intl.NumberFormat API instead.