Skip to content
Nana UI

Relative Time

View .md Download

Renders a localised, auto-updating relative timestamp — “2 hours ago”, “in 3 days” — from a date. It refreshes itself on a cadence proportional to the elapsed time (every second under a minute, every minute under an hour, and so on) and outputs a semantic <time> element carrying the machine readable datetime plus an absolute title for accessibility.

Terminal window
npm install @nana-tec/ui-components
import "@nana-tec/ui-components/relative-time";
<nana-relative-time date="2026-01-01T00:00:00Z"></nana-relative-time>

Properties

PropertyAttributeTypeDefaultDescription
dateDate | string | numbernew Date()The date — a `Date`, an ISO string, or a timestamp
formatRelativeTimeStyle'long'Wording length passed to `Intl.RelativeTimeFormat`
livebooleantrueKeep the value refreshing as time passes
localestring | undefinedBCP 47 locale (defaults to the document locale)
Explore Relative Time interactively Every state, prop, and edge case — with live controls — in Storybook.
View in Storybook