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 { For } from "solid-js";
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 class="flex flex-col gap-2 text-[13px]" role="list">
<For each={CITIES}>
{(entry) => (
<li class="text-muted-foreground flex items-center gap-3">
<span class="text-foreground w-20">{entry.city}</span>
<LocalTime timeZone={entry.timeZone}>
<LocalTimeClock class="text-foreground/90" />
<LocalTimeZone />
<LocalTimeDifference class="text-muted-foreground/80">
{(text) => `· ${text}`}
</LocalTimeDifference>
</LocalTime>
</li>
)}
</For>
</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-solid.jsonUsage
import {
LocalTime,
LocalTimeClock,
LocalTimeZone,
LocalTimeDifference,
} from "@/components/ui/local-time";<LocalTime timeZone="Europe/Warsaw">
<LocalTimeClock />
<LocalTimeZone />
<LocalTimeDifference />
</LocalTime>API Reference
Every part takes class for styling, and parts that wrap content take children. LocalTimeClock and LocalTimeZone take nothing else.
LocalTime
| Prop | Type | Default |
|---|---|---|
timeZone | string | – |
LocalTimeDifference
| Prop | Type | Default |
|---|---|---|
children | (text: string) => JSX.Element | – |