Skip to content

Local Time

Show the time in any time zone, with its offset and how far it is from the visitor.

Preview

  • WarsawGMT+1
  • New YorkGMT-5
  • TokyoGMT+9
import {
  LocalTime,
  LocalTimeClock,
  LocalTimeDifference,
  LocalTimeZone,
} from "@/components/ui/local-time";

const CITIES = [
  { city: "Warsaw", timeZone: "Europe/Warsaw" },
  { city: "New York", timeZone: "America/New_York" },
  { city: "Tokyo", timeZone: "Asia/Tokyo" },
];

export const LocalTimeExample = () => (
  <ul className="flex flex-col gap-2 text-[13px]" role="list">
    {CITIES.map((entry) => (
      <li
        className="text-muted-foreground flex items-center gap-3"
        key={entry.timeZone}
      >
        <span className="text-foreground w-20">{entry.city}</span>
        <LocalTime timeZone={entry.timeZone}>
          <LocalTimeClock className="text-foreground/90" />
          <LocalTimeZone />
          <LocalTimeDifference className="text-muted-foreground/80">
            {(text) => `· ${text}`}
          </LocalTimeDifference>
        </LocalTime>
      </li>
    ))}
  </ul>
);

Features

  • Ticks once a minute, on the minute.
  • Compares against the visitor only after hydration, so server and client markup match.
  • Split into parts. Render the clock, the offset, the difference, or all three.

Installation

bunx --bun shadcn@latest add https://olekaleksander.dev/r/local-time.json

Usage

import {
  LocalTime,
  LocalTimeClock,
  LocalTimeZone,
  LocalTimeDifference,
} from "@/components/ui/local-time";
<LocalTime timeZone="Europe/Warsaw">
  <LocalTimeClock />
  <LocalTimeZone />
  <LocalTimeDifference />
</LocalTime>

API Reference

Every part takes className for styling, and parts that wrap content take children. LocalTimeClock and LocalTimeZone take nothing else.

LocalTime

PropTypeDefault
timeZonestring–

LocalTimeDifference

PropTypeDefault
children(text: string) => ReactNode–