Skip to content
AZ Tools

Relative Time Formatter

Format any past or future date as 2 hours ago, in 3 days or last month — in 12 locales and three styles, with numeric: auto phrasing.

How to use

  1. Pick a target date. Leave the base on now for a live ticker, or uncheck to compare two fixed dates.
  2. Switch locale to see how Spanish, Korean, Arabic etc. render the same difference. The shape of the phrase often changes (RTL, particles, gendered nouns).
  3. Use the unit table to compare granularities side-by-side and pick the one that reads best in your interface.

About this tool

Show

A live workbench for the browser's built-in Intl.RelativeTimeFormat. Pick a target date and a base — by default now, ticking every second — and see the formatted string in the locale you choose. The unit table renders the same difference as seconds, minutes, hours, days, weeks, months, quarters and years at once, which is the fastest way to decide which granularity reads best in a given interface.

The numeric option is where the interesting behaviour lives. With always you get the plain arithmetic form: 1 day ago, in 1 day, and, at zero, the slightly awkward in 0 days. With auto the locale substitutes a word where it has one: English yields yesterday, today, tomorrow, last week, last quarter. Other languages go further than English can — Spanish returns anteayer for two days ago, a single word for a concept English needs three. That is the argument for auto in a multilingual interface: you get each language's idiom instead of a translated English sentence.

The API also handles plural agreement, which is the part hand-rolled formatters always get wrong. Russian needs 2 дня назад but 5 дней назад; Polish, Arabic and Welsh have their own category systems. A template that interpolates a number into a translated string cannot express that, and it is why this formatter exists in the platform rather than in your codebase.

One thing it deliberately does not do is choose the unit. You pass a value and a unit, and it formats exactly what you passed — including fractions, so -1.5 with day comes out as 1.5 days ago. Picking and rounding the unit is your code's job, and the honest version of that job has a subtlety: yesterday in most interfaces means the previous calendar date, not 24 hours ago. At 01:00 on Tuesday, an event at 23:00 on Monday is two hours old by arithmetic, and the formatter will say so. If you want it to say yesterday, compare calendar dates in the user's time zone before deciding the unit — the table here shows the arithmetic answer for every unit, which makes that mismatch easy to see.

Frequently asked questions

What's the difference between numeric: auto and always?

auto returns idiomatic phrasings when available — yesterday instead of 1 day ago, last week instead of 1 week ago. always forces the number, which is what you usually want for a literal duration display. UIs that want chat-style timestamps usually want auto.

Why does the same diff give different units?

The main output picks the largest unit where the absolute value ≥ 1 of that unit — so 90 minutes shows as 1 hour ago even though you could also say 90 minutes ago. The unit table lets you see every option.

Why does a relative timestamp go stale on the page?

Because it is computed once when rendered. A page open for an hour still says two minutes ago unless something re-renders it, and a server-rendered page bakes in the moment it was built, which a cache then serves to everyone. Recompute on the client on an interval, or put the exact time in a title attribute so the stale text is at least backed by something checkable.

When is a relative time the wrong choice?

Whenever the reader needs to act on the actual date: a deadline, an appointment, an expiry, anything they might quote to someone else. Three days ago hides which day it was, and eleven months ago hides the year entirely. Relative phrasing is good for recency in a feed and bad for a record — the common compromise is relative for the last day or two and an absolute date after that.

Related tools