Skip to content
Calm motion: animations on this site only fade, with no movement

RelativeTime ​

Time ago, in your language, kept up to date

A date as "3 hours ago" or "in 2 days", in the language of the reader. Use it in feeds, comments, and lists, where how long ago matters more than the exact date. For a date that people must read exactly, such as a due date in a contract, show the date.

Basic
  • Posted
  • Edited
  • Replied
  • Due
  • In German
  • Short
  • Live, counted from the time now (hover for the full date):
  • value is a Date, a timestamp in ms, or a date string. The element is a <time> with the exact datetime, so machines and screen readers can read the date. The tooltip shows the full date and time in the time zone of the reader.
  • The unit follows the distance: seconds, minutes, hours, days, months, years. numeric="auto" (default) writes "yesterday" and "now". numeric="always" writes "1 day ago". format is long, short, or narrow. The name is not style, because Vue reserves that one.
  • locale sets the language. The words come from Intl.RelativeTimeFormat, so there is nothing to translate by hand. Without locale, the text is English.
  • With live (default), the text updates while the page is open. It checks every 5 seconds for a fresh time, and less often for older ones. Turn it off with :live="false". The text is not a live region, so a screen reader does not announce each change.
  • The server and the browser disagree on the time now and on the time zone. So the server writes a plain date in UTC ("Oct 9, 2026"), and the relative text appears after mount. A fixed now is the same on both sides, so the relative text shows at once. Use now for tests and for a page that you render ahead of time.
  • An invalid value renders nothing.

Usage ​

ts
import { BlessRelativeTime } from "blessing-ui";

API ​

Props

NameTypeDefaultDescription
value*string | number | Date—a Date, a timestamp in ms, or a date string
localestring—language of the words, for example `de`. Default: English until you choose.
numeric"always" | "auto""auto"`auto` writes "yesterday" and "now". `always` writes "1 day ago".
format"long" | "short" | "narrow""long"`long` ("2 hours ago"), `short` ("2 hr. ago"), or `narrow`
livebooleantruekeep the text up to date while the page is open
nownumber | Date—the moment to count from. Default: the time now. Pass one for a fixed result.

Released under the MIT License. Character names and artwork belong to their owners.