Developer Tool

Relative Time Formatter

Paste a timestamp or date to see it rendered as relative time — "3 hours ago," "in 2 days" — the format almost every social feed and activity log uses.

Enter a timestamp or ISO date

Do it yourself — no library required

Every modern language has a built-in way to do this now, so pulling in a full library (like the now-legacy moment.js) usually isn't necessary anymore:

JavaScript: new Intl.RelativeTimeFormat('en', {numeric:'auto'}).format(-3, 'hour') → "3 hours ago". You calculate the numeric difference yourself; the API only handles the wording and pluralization.

Python: no single built-in one-liner — the standard approach is computing a timedelta and mapping the ranges manually, or using a small package like arrow or humanize for the wording.

PHP: pass a DateInterval to a manual formatter, or use a package like nesbot/carbon, which has ->diffForHumans() built in.

The part that's actually hard: picking thresholds

The tricky design decision isn't the math — it's choosing when to switch from relative to absolute. Most interfaces show relative time under about a week old ("3 days ago") and switch to an actual date beyond that ("March 3"), since "47 days ago" is harder to mentally place than a real date.

Related

Related tools