Skip to content

Date

A date people can read, with the machine-readable value in datetime, formatted at build time.

Native .astro · no React · MIT · free, no account

Updated

Install

Terminal
npx shadcn@latest add https://www.themes.dev/astro/r/time.json

The CLI needs a components.json (from npx shadcn init), which also writes the tokens these files use. No CLI? Copy the files below to the same paths.

Files

src/kit/components/Time.astroAstro
---// A date people can read, with the machine-readable value in datetime: <Time date={post.data.date} />.// Formatted at build time with Intl, in the language you pass (default en-GB: 23 November 2026).interface Props {  date: Date | string;  locale?: string;  format?: Intl.DateTimeFormatOptions;  class?: string;}const { locale = 'en-GB', format = { day: 'numeric', month: 'long', year: 'numeric' }, class: className } = Astro.props;const date = new Date(Astro.props.date);--- <time datetime={date.toISOString().slice(0, 10)} class={className}>{new Intl.DateTimeFormat(locale, { ...format, timeZone: 'UTC' }).format(date)}</time>