Datetime Picker Display Format

A date and time picker preset in the spectrumui registry that displays the selected value using the custom format "yyyy/MM/dd" via the displayFormat prop. It is a client component that wraps the datetime-picker base with local useState and a fixed w-72 width.

component · no preview
This item cannot be built as published, so there is no live preview: install:
See how it was built

Installation

pnpm dlx shadcn@latest add @spectrumui/datetime-picker-display-format

Requires @spectrumui in the registries of your components.json (shadcn adds official directory namespaces automatically).

Usage

usage.tsx
import React, { useState } from "react";import { DateTimePicker } from "@/components/ui/datetime-picker";export default function Example() {  const [date, setDate] = useState<Date | undefined>(undefined);  return (    <DateTimePicker      displayFormat={{ hour24: "yyyy/MM/dd" }}      value={date}      onChange={setDate}      className="w-72"    />  );}
  • When you need a date-only display in year/month/day slash format (yyyy/MM/dd) for a compact form field
  • When a date picker must sit in a fixed 18rem-wide column such as a sidebar or filter panel
  • When you want a copy-paste starting point that already wires displayFormat, value, and onChange with useState
  • When you need to customize how the picker's selected value is shown without changing the underlying date value

Examples

Default item component

The installed component as shipped in the registry, exported as the default export.

default-item-component.tsx
"use client";import React, { useState } from "react";import { DateTimePicker } from "@/components/ui/datetime-picker";const DatetimePickerDisplayFormat = () => {  const [date, setDate] = useState<Date | undefined>(undefined);  return (    <DateTimePicker      displayFormat={{ hour24: "yyyy/MM/dd" }}      value={date}      onChange={setDate}      className="w-72"    />  );};export default DatetimePickerDisplayFormat;

Preset value in a form row

Starts with a fixed date so the slash-formatted value is visible on first render.

preset-value-in-a-form-row.tsx
"use client";import React, { useState } from "react";import { DateTimePicker } from "@/components/ui/datetime-picker";export default function BirthdayField() {  const [date, setDate] = useState<Date | undefined>(new Date(2000, 0, 1));  return (    <div className="flex flex-col gap-2">      <label className="text-sm font-medium">Birthday</label>      <DateTimePicker        displayFormat={{ hour24: "yyyy/MM/dd" }}        value={date}        onChange={setDate}        className="w-72"      />    </div>  );}

Controlled value shared with parent state

Lifts the date state to a parent component so other UI can read the selected value.

controlled-value-shared-with-parent-state.tsx
"use client";import React, { useState } from "react";import { DateTimePicker } from "@/components/ui/datetime-picker";export default function FilterPanel() {  const [from, setFrom] = useState<Date | undefined>(undefined);  return (    <div className="space-y-2">      <DateTimePicker        displayFormat={{ hour24: "yyyy/MM/dd" }}        value={from}        onChange={setFrom}        className="w-72"      />      <p className="text-sm text-muted-foreground">        {from ? from.toISOString() : "No date selected"}      </p>    </div>  );}

API reference

PropTypeDefaultDescription
displayFormat{ hour24: string } (format options object; this item passes hour24 as a date-fns style pattern)—Controls how the selected date is rendered. This item sets hour24 to "yyyy/MM/dd" so the value shows as year/month/day with slashes.
valueDate | undefined—The currently selected date. Pass undefined for an empty picker.
onChange(date: Date | undefined) => void—Called with the new date when the user changes the selection. Passing the useState setter directly works because the item uses useState<Date | undefined>.
classNamestring—Additional Tailwind classes applied to the picker. This item uses "w-72" to set a fixed 18rem width.

Accessibility

  • The picker inherits keyboard and focus behavior from the datetime-picker base component; verify it in your installed version.
  • Pair the picker with a visible <label> (or aria-label) so screen readers announce the field purpose, as the item does not render one itself.
  • The slash format yyyy/MM/dd shows no time portion, so do not rely on it to communicate time-of-day to users.
  • Keep the w-72 width or a wider class so the formatted date does not truncate on small screens.

Docs written by anthropic:claude-haiku-5-5 from the registry source.

Use with Coding Agent

Paste this into Claude Code, Codex or Cursor. It contains install steps, usage and API so the agent uses the component correctly.

prompt.md
Use the "Datetime Picker Display Format" component (spectrumui/datetime-picker-display-format) from its shadcn registry.1. Install it with: npx shadcn@latest add @spectrumui/datetime-picker-display-format2. Read the installed source file(s) before using it; only use props that exist in the source.3. Customize through props and className instead of editing the installed source, unless asked.4. Available props: displayFormat, value, onChange, className.Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport React, { useState } from "react";import { DateTimePicker } from "@/components/ui/datetime-picker";export default function Example() {  const [date, setDate] = useState<Date | undefined>(undefined);  return (    <DateTimePicker      displayFormat={{ hour24: "yyyy/MM/dd" }}      value={date}      onChange={setDate}      className="w-72"    />  );}```

Files & dependencies

  • app/registry/datetime-picker/usage/datetime-picker-display-format.tsx→ components/spectrumui/datetime-picker-display-format.tsx
registryDependenciesdatetime-picker

Looks similar, elsewhere

There is no screenshot of this item to compare yet.