Skip to content

relativeTime
@localizer/format 1.1.1

The relativeTime calculates and formats the difference between two moments in time, presenting it as a human-readable relative duration (e.g., "5 minutes ago" or "in 2 hours"). It is useful for displaying time differences in a concise and intuitive manner.

Usage

typescript
import { 
relativeTime
} from '@localizer/format';
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
=
relativeTime
(
reference
,
value
);

Formatter accepts JavaScript Date objects or numbers, which are treated as timestamps (milliseconds since January 1, 1970, 00:00:00 UTC).

Demo

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