Skip to content
Eskais UI

Data

Relative Time

formatRelative() and formatInstant() on Date + Intl, a RelativeTime <time> with the absolute instant in its title, and a useNow hook that pauses while the page is hidden.

Example

Updated (UTC)
Actualizado (Madrid)

Installation

npx shadcn@latest add @eskais/relative-time
Brings alonglocale

Usage

Import
import { formatElapsed, formatInstant, formatRelative, toISO, toTime } from "@/lib/time"import { RelativeTime, useNow } from "@/components/ui/relative-time"import { useNow } from "@/components/ui/use-now"

API reference

RelativeTime

PropTypeDefault
valuerequiredInstant–
nowInstant–
localestring–
timeZonestring–
intervalMsnumber–
formatStyle"short" ("2 min. ago") or "narrow" where space is tight; "long" by default.Intl.RelativeTimeFormatStyle–

Also takes <time> attributes and render except children, dateTime.

Other exports

formatElapsedformatInstantformatRelativetoISOtoTimeuseNowtype FormatInstantOptionstype FormatRelativeOptionstype Instanttype RelativeTimePropstype UseNowOptions

Accessibility

  • A <time> element whose title holds the exact instant in the reader's time zone.

Agent actions

Runs agent.snapshot() from @ui-sdk/react/agent on the live preview above.