Examples

Past and future

live updates the text as time passes (every few seconds for recent times, less often later).

Preview

Edited

Comment posted

Deployed

Trial ends

Example.tsx
import { RelativeTime, Stack, Text } from '@reactloom/ui';

const now = Date.now();
const minute = 60_000;

export default function Example() {
  return (
    <Stack gap="2">
      <Text>
        Edited <RelativeTime date={now - 30 * 1000} live />
      </Text>
      <Text>
        Comment posted <RelativeTime date={now - 5 * minute} live />
      </Text>
      <Text>
        Deployed <RelativeTime date={now - 26 * 60 * minute} />
      </Text>
      <Text>
        Trial ends <RelativeTime date={now + 3 * 24 * 60 * minute} />
      </Text>
    </Stack>
  );
}

Style and threshold

Older dates switch to an absolute date after threshold milliseconds.

Preview

Short style:

Past the threshold, the date is shown:

Example.tsx
import { RelativeTime, Stack, Text } from '@reactloom/ui';

const day = 24 * 60 * 60_000;
const lastYear = Date.UTC(2025, 2, 14, 9, 30);

export default function Example() {
  return (
    <Stack gap="2">
      <Text>
        Short style: <RelativeTime date={Date.now() - 2 * day} unitStyle="short" />
      </Text>
      <Text>
        Past the threshold, the date is shown: <RelativeTime date={lastYear} threshold={7 * day} format={{ dateStyle: 'medium' }} />
      </Text>
    </Stack>
  );
}

API reference

RelativeTime props
PropTypeDefault
daterequired
The moment to describe.
Date | number | string—
live
Re-render as time passes.
booleanfalse
threshold
Beyond this many milliseconds, show the absolute date instead.
number—
format
Format of the absolute date (title and past the threshold).
Intl.DateTimeFormatOptions{ dateStyle: 'medium', timeStyle: 'short' }
numeric
“1 day ago” or “yesterday”.
'always' | 'auto''auto'
unitStyle
Unit length.
'long' | 'short' | 'narrow''long'

Customization

Extracted from the component’s source on every build, so it matches the code. How the layers fit together is explained in Customization.

Accessibility

  • Renders <time dateTime>; the exact date is available as its title.
  • The server renders the absolute date, and the relative text replaces it after hydration, so no mismatch occurs.
  • Live updates are not announced; put changing times outside live regions.

Usage guidelines

Do

  • Show the exact date nearby or in a tooltip when precision matters (invoices, audit logs).

Don’t

  • Don’t use relative times for dates people must compare or copy.