Skip to content

Timeago

Renders a timestamp as a relative time string ("3 minutes ago", "yesterday", etc.) with locale support.

bash
npm install @vuecs/timeago

Basic usage

vue
<script setup lang="ts">
import { VCTimeago } from '@vuecs/timeago';
const tenSecondsAgo = Date.now() - 10_000;
const oneHourAgo = Date.now() - 60 * 60 * 1000;
</script>

<template>
    <VCTimeago :datetime="tenSecondsAgo" />
    <VCTimeago :datetime="oneHourAgo" />
</template>
css
@import "tailwindcss";
@import "@vuecs/design";

@custom-variant dark (&:where(.dark, .dark *));

Locale switching

ts
import { injectLocale } from '@vuecs/timeago';
const locale = injectLocale();
locale.value = 'de';

The locale ref is provided by @vuecs/timeago at app install time. Mutate it to change the language for every <VCTimeago> instance reactively.

Props

PropTypeDefaultDescription
datetimenumber | string | DateThe timestamp to render relative to now

See also

Released under the Apache 2.0 License.