Formats a date relative to now as a human-readable string (e.g. "2 hours ago").
now
The date to describe.
Reference point. Defaults to new Date().
new Date()
const fiveMinutesAgo = new Date(Date.now() - 5 * 60 * 1000)formatRelativeTime(fiveMinutesAgo) // => "5 minutes ago"const tomorrow = new Date(Date.now() + 24 * 60 * 60 * 1000)formatRelativeTime(tomorrow) // => "in 1 day" Copy
const fiveMinutesAgo = new Date(Date.now() - 5 * 60 * 1000)formatRelativeTime(fiveMinutesAgo) // => "5 minutes ago"const tomorrow = new Date(Date.now() + 24 * 60 * 60 * 1000)formatRelativeTime(tomorrow) // => "in 1 day"
Formats a date relative to
nowas a human-readable string (e.g. "2 hours ago").