-
Notifications
You must be signed in to change notification settings - Fork 4
Function.formatRelativeTime
connor-baer edited this page Dec 5, 2024
·
3 revisions
@sumup-oss/intl / formatRelativeTime
formatRelativeTime(
value
,unit
,locales
?,options
?):string
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.