Relative time
A timestamp that reads as a distance from now ("3 minutes ago", "yesterday") and keeps itself current. It is a real time element with the exact moment in its dateTime and the full date as its title, in the reader's language.
Amara Okafor approved the Q4 budget
Elias Kim commented on Forma renewal
Aiko Tanaka closed INC-311
Dev Patel invited 3 people to Finance
When to use
- Feeds, comments, notifications and run histories, where recency matters more than the clock time.
- Lists of many rows: every instance on the page shares one 15-second clock.
When not to use
- Records where the exact time is the fact (an audit trail, an invoice date); show the date.
- Deadlines; say the date, and use the countdown for the last stretch.
Installation
pnpm dlx shadcn@latest add @caliper/relative-time
Adds its 2 files to components/ui/, each with its own stylesheet, and installs their packages. Pro installs with your access token, set up once per project. See Pro access. The first part also adds Caliper UI’s tokens; import them once as in Installation.
API reference
RelativeTime
4 props
Also accepts the native props of its root element and a ref.
formatRelative
0 props
No props of its own; it accepts the native props of its root element.
Keyboard
- No custom key handling; Tab and the native activation keys do the work.
Accessibility
It is built on native elements, so roles and focus come from the browser.
Notes for AI
Give your coding assistant this page as Markdown instead of screenshots: the props, keyboard and examples in one file.
/docs/components/relative-time.mdThe index of every part is at /llms.txt.