Date & Time

Relative Timestamp: Convert Dates to Relative Time Strings Like "3 Days Ago"

Convert any date or Unix timestamp into a natural relative time string like "3 hours ago" or "in 2 weeks" — with locale and threshold controls.

Published January 15, 2025Updated June 1, 20254 min read

Try the free online tool

Runs entirely in your browser — no signup, no uploads.

Open Tool

Absolute timestamps like '2025-03-14T15:09:26Z' are precise and machine-friendly, but they force users to do mental arithmetic to understand how long ago something happened. Relative time strings like '3 hours ago,' 'yesterday,' or 'in 2 weeks' communicate the same information in a way that is immediately intuitive. Almost every social platform, version control system, and content management tool uses relative timestamps in their interfaces for this reason.

Our Relative Timestamp tool converts any date, time, or Unix timestamp into a natural-language relative time string, calculated from the current moment or from any reference time you specify. You can control the precision threshold — for example, showing 'just now' for anything within the last minute, switching to hours for anything within the last 24 hours, and using full dates for anything older than a week.

The tool also generates the code snippet you need to implement the same behavior in JavaScript, Python, or your preferred language, using native APIs like Intl.RelativeTimeFormat or popular libraries like day.js and date-fns, so you can replicate the exact display logic in your own application.

What Is a Relative Timestamp?

A relative timestamp expresses a point in time in relation to another point — usually the current moment — using natural language. Instead of 'March 14, 2025, 3:09 PM,' a relative timestamp might say '2 months ago.' Instead of 'June 1, 2025, 9:00 AM,' it might say 'in 3 weeks.' The exact wording depends on the magnitude of the difference and the rounding rules applied.

Relative timestamps are inherently dynamic: the same absolute date produces a different relative string depending on when it is evaluated. '3 hours ago' becomes '4 hours ago' an hour later. This means relative timestamps should generally be recalculated on render or updated via a timer, never stored as static strings.

Most modern applications use a tiered system: very recent events get second or minute precision ('just now,' '5 minutes ago'), recent events get hour precision ('3 hours ago'), older events get day precision ('yesterday,' '3 days ago'), and distant events fall back to an absolute date. The specific thresholds vary by application and user expectation.

How to Use This Tool

Generate a relative time string from any date in a few steps:

  1. 1

    Enter Your Date or Timestamp

    Paste a Unix timestamp, an ISO 8601 date string, or use the date-time picker to select a specific moment. The tool accepts all common date formats automatically.

  2. 2

    Set the Reference Time

    By default, relative strings are calculated from 'now' (the current moment). Toggle the custom reference option to compare against any specific date and time instead — useful for testing how a relative string will look at a future point.

  3. 3

    Configure Thresholds

    Use the threshold panel to define when the string switches from seconds to minutes to hours to days to weeks. You can also customize the cutoff beyond which the tool shows an absolute date instead of a relative string.

  4. 4

    Select Locale and Style

    Choose a locale (en-US, fr-FR, ja-JP, etc.) to get locale-appropriate phrasing. Select 'short' style for compact strings ('3 hr. ago') or 'long' for natural prose ('3 hours ago').

  5. 5

    Copy the String or the Code

    Copy the generated relative string directly, or switch to the Code tab to get a ready-to-use snippet in JavaScript (using Intl.RelativeTimeFormat), Python (using arrow or humanize), or TypeScript.

Common Use Cases

Relative timestamps appear in almost every user-facing application:

  • Displaying comment, post, and activity timestamps in social networks, forums, and collaborative tools where recency context matters more than absolute precision
  • Showing file modification times in version control interfaces, code review tools, and file managers in a way that conveys freshness at a glance
  • Building notification and feed systems where items are sorted by recency and users need to understand at a glance how old each item is
  • Displaying SLA timers, ticket ages, and response times in support and operations dashboards where relative urgency is the primary concern
  • Testing and verifying the relative time display logic in your own application by quickly checking what string a specific timestamp should produce at a given reference time

Tips and Best Practices

Implement relative timestamps correctly in your application with these practices:

  • Always store and use the absolute timestamp in your data model — compute the relative string at render time, and update it with a periodic timer (every 60 seconds is usually sufficient) so it stays accurate
  • Use the browser's native Intl.RelativeTimeFormat API for locale-aware relative strings rather than hardcoding English phrases — this handles pluralization and phrasing differences automatically across languages
  • Include the absolute timestamp in a tooltip on the relative string so users can see the precise time when they need it — this gives the best of both worlds
  • Define clear thresholds for your application and document them: decide exactly when 'just now' becomes 'a minute ago,' when 'yesterday' becomes '2 days ago,' and when relative strings give way to absolute dates
  • Consider accessibility: screen readers and users who have difficulty with relative time concepts benefit from the tooltip or aria-label containing the full absolute date and time

Frequently Asked Questions

How do I implement 'time ago' in JavaScript?

Use the native Intl.RelativeTimeFormat API: const rtf = new Intl.RelativeTimeFormat('en', { numeric: 'auto' }); then call rtf.format(-3, 'hour') to get '3 hours ago'. For a full implementation that automatically selects the appropriate unit, see the code snippet generated by this tool.

What is the difference between 'numeric: auto' and 'numeric: always' in Intl.RelativeTimeFormat?

With 'numeric: auto', the formatter produces natural phrasing like 'yesterday' and 'tomorrow' when appropriate. With 'numeric: always', it always uses numeric forms like '1 day ago' and 'in 1 day.' The 'auto' setting generally produces more natural-feeling output for user interfaces.

How do I handle the transition from relative to absolute display?

Define a maximum age threshold — for example, 30 days — beyond which you show the full absolute date instead of a relative string. This prevents unhelpful strings like '11 months ago' where the absolute date is more informative. The tool lets you configure and preview this threshold interactively.

How often should I update relative timestamps on a page?

For items up to an hour old, update every 60 seconds. For items up to a day old, updating every 5 minutes is sufficient. For older items, the relative string changes slowly enough that updating on page load or navigation is adequate. Avoid updating every second, as it is visually distracting and wastes resources.

Can I generate relative timestamps for future dates?

Yes. The tool handles future dates with forward-looking phrasing: 'in 3 hours,' 'in 2 weeks,' 'next month.' The same threshold and locale settings apply. This is useful for countdown displays, scheduled event listings, and deadline indicators.

Does Intl.RelativeTimeFormat work in all browsers?

Yes. Intl.RelativeTimeFormat is supported in all modern browsers (Chrome 71+, Firefox 65+, Safari 14+, Edge 79+) and in Node.js 12+. For older environments, libraries like date-fns (formatDistanceToNow) and day.js (fromNow plugin) provide equivalent functionality with broader compatibility.

How do I show relative time in a language other than English?

Pass the locale code as the first argument to Intl.RelativeTimeFormat — for example, 'fr' for French, 'de' for German, 'ja' for Japanese. The API handles all locale-specific phrasing, pluralization rules, and grammatical structure automatically. Use this tool's locale selector to preview the output before implementing it.

relative timestamptime agorelative timedate formattinghuman-readable timedeveloper tools

Ready to use this tool?

Free, instant, no account required. Runs entirely in your browser.

Open Tool

More Date & Time Guides