Date
Date formats one instant in a time zone you pass as timezone. The same timestamp reads as London, New York or Tokyo time. showTimezone underlines the date. Hover one to see that zone beside UTC.
@dentil/dateOn this page
'use client';
import { Date } from '@/components/dentil/date/date';
/** 7 Nov 2026, 09:14 UTC. */
const created = 1_794_042_840;
const zones = [
['London', 'Europe/London'],
['New York', 'America/New_York'],
['Tokyo', 'Asia/Tokyo'],
] as const;
export function DateOverviewDemo() {
return (
<div className="flex w-full max-w-sm flex-col gap-2 text-sm">
{zones.map(([label, timezone]) => (
<div key={timezone} className="flex items-baseline justify-between gap-6">
<span className="text-muted-foreground">{label}</span>
<Date date={created} timezone={timezone} showTimezone hover align="end" />
</div>
))}
</div>
);
}Installation
pnpm dlx shadcn@latest add @dentil/datenpx shadcn@latest add @dentil/dateyarn dlx shadcn@latest add @dentil/datebunx --bun shadcn@latest add @dentil/dateFiles land in components/dentil/date/. It uses Intl.DateTimeFormat and the stock Popover and HoverCard. Pass an IANA name such as Europe/London. There is no provider.
Usage
import { Date } from '@/components/dentil/date/date';
// 7 Nov 2026, 09:14 UTC. Unix seconds, milliseconds, an ISO string or a Date all work.
const created = 1_794_042_840;
<Date date={created} timezone="Europe/London" />
<Date date={created} timezone="America/New_York" showTimezone hover side="top" align="end" />
<Date date={created} timezone="Europe/London" showTime={false} showYear />The year is omitted when the date is in the current year in timezone. showYear puts it back. The popover always shows the clock time, including when the date itself hides it. hover opens it on hover and keeps it open while the pointer is over the popover. side and align set where it opens. formatDate and toDate live in components/dentil/date/format, so a server component can call them without pulling in the client component. formatDate appends the short zone name when showTimezone is set, instead of opening a popover.
Examples
Format
Turn the time off for a date, or pass a past year and the year appears on its own. An empty value renders fallback.
'use client';
import { Date } from '@/components/dentil/date/date';
/** 7 Nov 2026, 09:14 UTC. */
const created = 1_794_042_840;
/** 4 Mar 2024, 14:30 UTC. */
const older = 1_709_562_600;
const rows = [
['This year', <Date key="year" date={created} timezone="Europe/London" />],
['Date only', <Date key="date" date={created} timezone="Europe/London" showTime={false} />],
['Another year', <Date key="older" date={older} timezone="Europe/London" />],
['Forced year', <Date key="forced" date={created} timezone="Europe/London" showYear />],
['Missing', <Date key="missing" date={null} fallback="—" />],
] as const;
export function DateFormatDemo() {
return (
<div className="flex w-full max-w-sm flex-col gap-2 text-sm">
{rows.map(([label, value]) => (
<div key={label} className="flex items-baseline justify-between gap-6">
<span className="text-muted-foreground">{label}</span>
{value}
</div>
))}
</div>
);
}API reference
Date
| Prop | Type | Default | Description |
|---|---|---|---|
| date | number | string | Date | null | undefined | — | Unix seconds, unix milliseconds, an ISO string or a Date. Anything above 1e11 is treated as milliseconds. Empty or invalid values render fallback. |
| timezone | string | — | IANA time zone the value is formatted in, such as Europe/London. Omit it to use the runtime zone, which can differ between server and client. An unknown name is formatted as UTC. |
| locale | string | — | BCP 47 language tag passed to Intl.DateTimeFormat. Omit it to use the runtime locale. |
| showTime | boolean | true | Include the time in 24-hour form, such as 09:14. |
| showYear | boolean | false | Include the year even when the date falls in the current year in timezone. |
| showTimezone | boolean | false | Underlines the date and opens a popover with the time in timezone and the same instant in UTC. Click it, or hover when hover is set. |
| hover | boolean | false | Opens the popover while the pointer is over the date or the popover. Clicking and the keyboard still open it. Ignored unless showTimezone is set. |
| side | 'top' | 'right' | 'bottom' | 'left' | 'bottom' | Side of the date the popover opens on. |
| align | 'start' | 'center' | 'end' | 'start' | Alignment of the popover along that side. |
| fallback | ReactNode | null | Rendered when date is null, undefined, an empty string or invalid. |
| className | string | — | Merged onto the date. With showTimezone, that is the button that opens the popover. |
| …props | Omit<ComponentProps<'time'>, 'dateTime' | 'children'> | — | Other props are passed to the time element. dateTime is the UTC ISO string. |
formatDate
formatDate(value, options) from @/components/dentil/date/format returns the compact string, or null. With showTimezone it appends the short zone name.
| Prop | Type | Default | Description |
|---|---|---|---|
| value | number | string | Date | null | undefined | — | Same values as the date prop. Returns null when the value cannot be parsed. |
| timezone | string | — | IANA time zone. Omit it to use the runtime zone. An unknown name is formatted as UTC. |
| locale | string | — | BCP 47 language tag. Omit it to use the runtime locale. |
| showTime | boolean | true | Include the 24-hour time. |
| showYear | boolean | false | Include the year even when the date is in the current year. |
| showTimezone | boolean | false | Append the short zone name to the returned string. |
toDate
toDate(value) returns a Date or null.
| Prop | Type | Default | Description |
|---|---|---|---|
| value | number | string | Date | null | undefined | — | Unix seconds, unix milliseconds, an ISO string or a Date. Returns null for empty or invalid values. |