Relative Time
A timestamp that reads "3 minutes ago" and keeps itself up to date.
Just now
Seconds
Minutes
Hours
Yesterday
Weeks
Future
Installation
Run the following command to install the `relative-time` components:
npx shadcn-svelte@latest add https://more-shadcn.noair.fun/r/relative-time.json
Staying current
Every instance on the page shares one timer, and that timer only runs as often as the freshest
timestamp needs: every second for "12 seconds ago", every ten seconds for minutes, and every
few minutes once everything is days old. A feed of two hundred timestamps still costs one
interval — and none at all when nothing is live. Background tabs catch up the moment they
become visible.
Event #1
Formatting
Text comes from
Intl.RelativeTimeFormat, so it is localised for free. The style prop picks between long, short and narrow, and numeric="auto" (the default) prefers words like "yesterday" and "now" over "1 day ago". Hover any timestamp for
the exact date and time.locale long short numeric always
en
de
fr
ja
ar
Switching to a date
Past a certain age, a plain date reads better than "7 months ago". Set
absoluteAfter in milliseconds and older timestamps show the date instead — month and
day, plus the year when it is not the current one.under 1 days old
3 days old
45 days old
400 days old
Outside the markup
formatRelative is the same logic as a plain function, for titles, notifications or
anywhere a component does not fit.