Relative Time

React relative timestamp that renders just now, 5m ago, 3h ago or 2d ago inside a semantic time element, with the full local date shown as a hover title.

src/registry/ui/relative-time.tsx/r/relative-time.json

Installation#

bash
npx shadcn@latest add @minidev/relative-time

MiniDev UI is in the shadcn registry directory, so the short form works with no setup. Older CLI versions can use the full URL: npx shadcn@latest add https://ui.minidev.pro/r/relative-time.json

Usage#

tsx
import { RelativeTime } from "@/components/ui/relative-time"

export function Example() {
  return <RelativeTime />
}

API reference#

RelativeTime props
PropTypeDefault
datestring | Date-
classNamestring-
All Developer tool UI components for React

Learn more