Render “3 days ago”, “in 2 hours”, “next week”, etc. across any locale using the browser's built-in Intl.RelativeTimeFormat. Includes a date-diff auto-bucketing helper so you can paste two timestamps and get the most natural unit out.
Pass a numeric value — positive is future, negative is past.
Pick the largest unit that produces a whole-number value ≥ 1. The result drives the formatter above when you click Use bucket.
| Locale | numeric: auto | numeric: always |
|---|
Intl.RelativeTimeFormat turns a numeric offset plus a unit (day, hour, …)
into a localized phrase: “3 days ago”, “dans 3 jours”, “3 يوم مضت”.
With numeric: 'auto' the formatter substitutes natural-language shorthand where available — you'll see
“yesterday”, “next month”, “last year”. Only seven units are part of the spec, so a
diff in milliseconds needs to be bucketed into the most natural one first; the helper above implements the common
approach (largest unit with absolute value ≥ 1).