Relative Time Display: '2 Hours Ago' vs Raw Timestamps
Implement relative time strings like '5 minutes ago' using Intl.RelativeTimeFormat and custom logic. Covers thresholds and live updates.
Published:
Tags: developer-tools, timestamps, ui
Relative Time Display: Show "2 Hours Ago" Instead of Raw Timestamps Raw timestamps like are precise, but they make users do mental arithmetic. For activity feeds, comments, notifications, and log entries, relative time — "2 hours ago", "yesterday", "last week" — communicates the information users actually care about: how recent is this? This guide covers how to implement relative time in JavaScript and Python, when to switch from relative to absolute display, and UX patterns that get this right. --- The Logic: Thresholds and Buckets Relative time works by computing the difference between now and the timestamp, then mapping that difference to a human-readable bucket: The exact thresholds are a UX decision — different applications use different cutoffs. What matters is consistency. ---…
All articles · theproductguy.in