Dashral Pro is hereSee pricing

Dashral

Relative TimeNew

A moment as people say it, "3 minutes ago", in the reader's language and kept current.

$ pnpm dlx shadcn@latest add @dashral/relative-time
Just now
Minutes
Hours
Yesterday
Weeks
Future

Installation

$ pnpm dlx shadcn@latest add @dashral/relative-time

Adds the component, the components it builds on, its npm packages and the theme tokens it uses. Or by its full URL: https://dashral.com/r/relative-time.json

Usage

example.tsx
import { RelativeTime } from "@/components/dashral/relative-time"

<RelativeTime date={comment.createdAt} />

Using the npm package? Import from @dashral/ui/components/relative-time instead, here and in the examples; the rest is the same.

Examples

Styles

long, short or narrow; absoluteAfterDays shows the date itself past a limit.

long
short
narrow
absoluteAfterDays={30}

Activity feed

A new entry reads "now" and ages on its own, with no refresh.

  • ANArif Nugroho

    Arif Nugroho paid INV-1047

  • SDSinta Dewi

    Sinta Dewi invited Daniel Lee

API reference

RelativeTime

Also takes every prop of <time>(opens in a new tab).

PropTypeDefault
dateDate | string | number

The moment, past or future. Required.

—
style"long" | "short" | "narrow"

"3 minutes ago", "3 min. ago" or "3m ago", as the locale writes them.

"long"
absoluteAfterDaysnumber

Past this many days, the date itself instead.

—
formatOptionsIntl.DateTimeFormatOptions

How that date is written.

{ dateStyle: "medium" }
titleFormatOptionsIntl.DateTimeFormatOptions

The full date on hover.

{ dateStyle: "full", timeStyle: "short" }
liveboolean

Keeps it current: each 15 s under a minute, 30 s under an hour, then less often.

true
localestring

BCP 47 locale.

the LocaleProvider's
classNamestring

Extra classes, merged with cn() so yours win.

—

Accessibility

  • A <time> with the exact moment in dateTime, so assistive technology and machines read the real date.
  • Words come from the browser's Intl in the page's locale ("yesterday", "kemarin", "أمس"), so they need no translation.
  • The server writes it from its clock; the browser corrects it as it loads, without a hydration warning.