javascript-time-ago
javascript-time-ago copied to clipboard
Seconds and minutes
How can we accomplish:
2s ago 1m 22s ago 1h 2m 33s ago
Hmm.
For that you could use just RelativeTimeFormat:
const days= interval / (24 * 60 * 60 * 1000)
const hours = (interval - days * 24 * 60 * 60 * 1000) / 60 * 60 * 1000
...
const formatter = new RelativeTimeFormat(('en', { style: 'narrow' })
formatter.format(days, 'days') + ' ' + formatter .format(hours, 'hours') + ...