Componentmedia0.57 KB gzipZero dependencies
TimeAgo
Relative time display showing '5 MIN AGO' with live re-render tick every 30s
Preview
Live Preview
Installation
Tokens guide →Add to your project via CLI (zero dependencies, code you own):
npx bigbullui add time-agoOr install the full npm package:
npm install bigbulluiUsage
tsx3 lines
import { TimeAgo } from "@/components/ui/time-ago" <TimeAgo date={new Date()} live />Source code
time-ago.tsx + 1 helperZero third-party dependencies (2 local files shown in tabs below).
tsxtime-ago.tsx64 lines
"use client";import * as React from "react";import { cn } from "./lib/utils"; export type TimeAgoProps = { date: Date | number | string; live?: boolean;}; function formatTimeAgo(date: Date | number | string): string { const now = new Date(); const target = typeof date === "number" ? new Date(date) : new Date(date); if (Number.isNaN(target.getTime())) return "UNKNOWN"; const diffMs = now.getTime() - target.getTime(); const isFuture = diffMs < 0; const diffSec = Math.floor(Math.abs(diffMs) / 1000); const diffMin = Math.floor(diffSec / 60); const diffHour = Math.floor(diffMin / 60);Props
Interactive Prop Playground
Tweak parsed AST props below to generate ready-to-paste JSX.
tsx3 lines
import { TimeAgo } from "@/components/ui/time-ago"; <TimeAgo />| Prop | Type | Description |
|---|---|---|
| date | Date | number | string | The date to calculate relative time from |
| live | boolean | Whether to live-update the relative time every 30s |