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
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 मिनट पहले |