Add this component

npx zentauri-ui add relative-time

Accessibility notes

Keyboard accessible by default with semantic markup, visible focus treatment, and tokenized states. Add descriptive labels for icon-only or decorative usage.

Dependency notes

Check Installation for shared peers. This component keeps styling in Tailwind classes and the --zui-* token contract.

Intl & Time

Relative Time

Display human-readable relative timestamps that update automatically in real time. Works with any Date, number, or ISO string input.

Relative time variants playground

Pick an appearance and size to preview the relative time live. Toggle Show output / Show code and the snippet updates to match the selected variant.


Relative Time API

Generated from the package prop types and variant definitions.

RelativeTime

RelativeTimeProps

Variants

PropTypeDefault
appearance
badgebluedefaultghostgreenoutlineprimaryredsecondary
default
size
lgmdsm
md

Behavior

PropTypeDefault
absoluteAfter{ unit: RelativeTimeUnit; count: number; } | undefinednone
date*string | number | Datenone
formatStyleIntl.RelativeTimeFormatStyle | undefinednone
liveboolean | undefinednone
localestring | string[] | undefinednone
numericIntl.RelativeTimeFormatNumeric | undefinednone
ssrFallbackReactNodenone
tooltipFormatOptionsIntl.DateTimeFormatOptions | undefinednone
withTooltipboolean | undefinednone
Inherited HTML props
PropTypeDefault
classNamestring | undefinednone
idstring | undefinednone
onClickMouseEventHandler<HTMLTimeElement> | undefinednone
styleCSSProperties | undefinednone
titlestring | undefinednone

RelativeTimeVariant

RelativeTimeVariantProps

Behavior

PropTypeDefault
appearance'default' | 'outline' | 'ghost' | 'blue' | 'green' | 'red' | 'secondary' | 'primary' | 'badge' | null | undefinednone
size'md' | 'sm' | 'lg' | null | undefinednone

RelativeTimeAnimated

RelativeTimeAnimatedProps

animated

Behavior

PropTypeDefault
absoluteAfter{ unit: RelativeTimeUnit; count: number; } | undefinednone
animationRelativeTimeAnimation | undefinednone
appearance'default' | 'outline' | 'ghost' | 'blue' | 'green' | 'red' | 'secondary' | 'primary' | 'badge' | null | undefinednone
date*string | number | Datenone
formatStyleIntl.RelativeTimeFormatStyle | undefinednone
liveboolean | undefinednone
localestring | string[] | undefinednone
numericIntl.RelativeTimeFormatNumeric | undefinednone
size'md' | 'sm' | 'lg' | null | undefinednone
ssrFallbackReactNodenone
tooltipFormatOptionsIntl.DateTimeFormatOptions | undefinednone
withTooltipboolean | undefinednone
Inherited HTML props
PropTypeDefault
classNamestring | undefinednone
idstring | undefinednone
onClickMouseEventHandler<HTMLTimeElement> | undefinednone
styleCSSProperties | undefinednone
titlestring | undefinednone

What it does

RelativeTime renders a semantic <time> element that displays a timestamp as a human-friendly relative string — "3 minutes ago", "in 2 hours", "last week" — using Intl.RelativeTimeFormat. It automatically re-computes on a dynamic interval so the displayed value always stays current.

API

Accepts a datetime prop (Date, number, or ISO 8601 string) and an optional locale. Renders a native <time> with the correct datetime attribute for machine readability.

Common use cases

  • Showing comment timestamps on posts and discussions
  • Displaying "last seen" indicators for user presence
  • Activity feeds and audit logs with human-readable times

Accessibility

The component uses a native <time> element with a proper datetime attribute, ensuring screen readers and SEO crawlers always have access to the absolute machine-readable timestamp.

Next.js integration notes

Works out of the box with both Pages Router and App Router. Use a dynamic import with ssr: true (default) for best SEO, or ssr: false for purely client-side timestamps.

FAQ

How often does the component update?

The component re-renders on a smart schedule — every second for "just now" intervals, then backs off to minute, hour, and day granularity as the timestamp ages.

Does it work with server-side rendering?

Yes. The initial timestamp is rendered on the server and the live update kicks in after hydration on the client.