ts-humanize / relativeTime
relativeTime(
timeInPast,timeInFuture):string
Defined in: time/time.ts:27
Returns a human-readable relative time string between two dates/times.
The earlier time (Date or Dayjs instance).
Dayjs | Date
The later time (Date or Dayjs instance). Optional/Defaults to the current time.
Dayjs | Date
string
A string describing the relative time (e.g., "2 hours ago", "in 5 minutes").
relativeTime(new Date('2024-06-01T10:00:00Z'), new Date('2024-06-01T12:00:00Z'));
// => "2 hours ago"relativeTime(dayjs().subtract(1, 'day'));
// => "a day ago"relativeTime(dayjs(), dayjs().add(3, 'days'));
// => "in 3 days"