Skip to main content

Time distance

TimeDistance displays how far a moment is from now, in the largest sensible unit, inside a semantic <time> element whose title holds the exact timestamp.

Example

<TimeDistance date="2020-01-01T00:00:00" />

Usage

<TimeDistance
date={comment.createdAt}
beforeWord=" ago"
afterWord=" later"
unitWords={{ D: 'day(s)', H: 'hour(s)', m: 'minute(s)' }}
/>

unitWords localizes the unit labels, while beforeWord and afterWord are appended for past and future moments respectively.