📅Date & Time

Relative Time Patterns

Human-readable relative time strings like "2 hours ago".

Explanation

Relative time is often more useful for UI/UX than absolute timestamps for recent events.

Examples

Past
Output
5 minutes ago
Future
Output
in 3 days
Just now
Output
just now

Code Examples

JavaScript (Intl)
const rtf = new Intl.RelativeTimeFormat('en', { numeric: 'auto' });
console.log(rtf.format(-2, 'day')); // "2 days ago"
console.log(rtf.format(1, 'month')); // "next month"

💡 Tips

  • Use "just now" for very recent events
  • Switch to absolute dates after 24-48 hours
  • Localize strings for non-English users

⚠️ Common Pitfalls

  • Avoid being too precise (e.g., "5 minutes and 23 seconds ago")
  • Don't use relative time for future deadlines without absolute backup