Relative Time Formatter ("2 hours ago")
Apps everywhere display timestamps as "5 minutes ago" instead of raw dates because relative phrases are easier to scan. Building this manually means handling pluralization, locale-specific word order, and unit thresholds — all of which the browser's Intl.RelativeTimeFormat handles for you. This tool wraps the browser API: pick a target date and locale, get the localized relative phrase, and see the actual API call you'd use in your own code.
How to use the Relative Time Formatter ("2 hours ago")
Pick a target datetime — relative to "now" — and a locale. The output shows the relative phrase in that locale, the unit that was auto-selected (e.g. "minutes" for a 30-minute offset), and the exact Intl.RelativeTimeFormat code snippet to reproduce it. Auto numeric mode swaps in idiomatic forms like "yesterday" or "tomorrow" where the locale has them; always mode always uses the numeric form.
Quick buttons let you jump between common offsets without typing dates.
About Relative Time Formatter ("2 hours ago")
Intl.RelativeTimeFormat is a standard browser API for producing locale-aware "5 minutes ago" / "in 3 days" strings. It handles pluralization (one minute / 2 minutes / 0 minutes), word order, and translation in every locale the browser ships — typically 250+ locales on modern Chrome / Firefox / Safari. You call new Intl.RelativeTimeFormat(locale, options).format(value, unit) with a signed numeric value (negative = past, positive = future) and a unit ("second" / "minute" / "hour" / "day" / "week" / "month" / "quarter" / "year"). The API does not pick the unit for you — that is your responsibility.
Auto-bucketing the offset (e.g. picking "hours" for 7200 seconds, "days" for 600 000) is a common helper pattern: pick the largest unit where the rounded magnitude is ≥ 1, round, then format. Edge cases include "0 days ago" vs "today" (use numeric: "auto" to get "today" / "now" where idiomatic), and timezone handling for cross-day boundaries.
For server-side use (Node 14+ / Bun / Deno), the same API is available without any polyfill. For older browsers, the FormatJS polyfill ships locale data alongside the polyfill.
Common use cases
- Activity feeds — display when items were created without overwhelming the user with full datetimes.
- Notification timestamps — "5 min ago" reads faster than "14:30:22 UTC".
- Deadline displays — countdown to event in user's language ("in 3 days" in English, "dans 3 jours" in French).
- Logs and timelines — admin dashboards showing recent activity.
- Email and push notifications — server-side rendering using Node's built-in
Intl.RelativeTimeFormat.
Frequently asked questions
Why "auto" sometimes shows "yesterday" and sometimes "1 day ago"?
Does the API auto-pick the unit?
Are weeks counted as 7 days or by calendar week boundary?
Server-side support?
full-icu data and the FormatJS polyfill for full locale coverage.