amankaushik481

Relative Time

Component

About

A React time element that renders a human-readable relative timestamp like "just now", "5m ago" or "3h ago", with the full local date shown on hover and an optional live-updating mode.

Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Relative Time to your project and fits it to your theme.

Code

How Relative Time is used: the demo's code. The component's own source comes with a free account.

Usage.tsx

import { RelativeTime } from "@/components/ui/relative-time";

export default function RelativeTimeDemo() {
  const minutesAgo = (m: number) => new Date(Date.now() - m * 60_000);

  return (
    <div className="flex flex-col gap-2">
      <RelativeTime date={minutesAgo(0)} />
      <RelativeTime date={minutesAgo(12)} />
      <RelativeTime date={minutesAgo(5 * 60)} />
      <RelativeTime date={minutesAgo(3 * 24 * 60)} />
    </div>
  );
}

More by amankaushik481

View all
  • Chip Filter

    Chip Filter

    7
  • Icon Button

    Icon Button

    4
  • Emoji Picker

    Emoji Picker

    4
  • Morphing Text

    Morphing Text

    2
  • Product Card

    Product Card

  • Floating Label Input

    Floating Label Input

  • Link Preview

    Link Preview

  • Order Summary

    Order Summary