useDate
Date manipulation with a plain JavaScript Date default, locale-aware formatting, and an adapter you can swap. Pass V0DateAdapter when you want Temporal.
Installation
The built-in V0DateAdapter uses the runtime’s native Temporal implementation when available. Runtimes without native Temporal need the @js-temporal/polyfill optional peer:
pnpm add @js-temporal/polyfillnpm install @js-temporal/polyfillyarn add @js-temporal/polyfillbun add @js-temporal/polyfill The Temporal API reached Stage 4↗︎ (finished) at TC39 in January 2026 and is part of ECMAScript 2026. The adapter prefers native globalThis.Temporal and falls back to the polyfill. Loading V0DateAdapter always resolves the static polyfill import, so the package stays installed even when the runtime has native Temporal.
Then install the date plugin with an adapter:
import { V0DateAdapter } from '@vuetify/v0/date'
import { createDatePlugin } from '@vuetify/v0'
app.use(
createDatePlugin({
adapter: new V0DateAdapter(),
locale: 'en-US',
})
) The adapter option is optional. Omit it and createDate() / useDate() inside a component use V0PlainDateAdapter. Pass V0DateAdapter for Temporal. That class is exported from @vuetify/v0/date so the Temporal polyfill stays out of the main entry. useDate() outside a component still throws.
Usage
Once the plugin is installed, use the useDate composable in any component:
Adapters
Adapters let you swap the underlying date library without changing your application code.
| Adapter | Import | Description |
|---|---|---|
V0PlainDateAdapter | @vuetify/v0 | JavaScript Date. Default when no adapter is passed |
V0DateAdapter | @vuetify/v0/date | Temporal API↗︎ adapter[1] |
DateAdapter Interface
The adapter provides a comprehensive API compatible with date-io↗︎:
Format Presets
The format() method accepts these preset format strings:
| Preset | Example Output |
|---|---|
fullDate | Saturday, June 15, 2024 |
fullDateWithWeekday | Saturday, June 15, 2024 |
normalDate | Jun 15, 2024 |
shortDate | 6/15/24 |
year | 2024 |
month | June |
monthShort | Jun |
monthAndYear | June 2024 |
monthAndDate | June 15 |
weekday | Saturday |
weekdayShort | Sat |
dayOfMonth | 15 |
hours12h | 10 AM |
hours24h | 10 |
minutes | 30 |
seconds | 45 |
fullTime | 10:30 AM |
fullTime12h | 10:30 AM |
fullTime24h | 10:30 |
fullDateTime | Saturday, June 15, 2024 at 10:30 AM |
fullDateTime12h | Saturday, June 15, 2024 at 10:30 AM |
fullDateTime24h | Saturday, June 15, 2024 at 10:30 |
keyboardDate | 06/15/2024 |
keyboardDateTime | 06/15/2024 10:30 AM |
keyboardDateTime12h | 06/15/2024, 10:30 AM |
keyboardDateTime24h | 06/15/2024, 10:30 |
Format Tokens
The formatByString() method supports these tokens:
| Token | Output | Example |
|---|---|---|
YYYY | 4-digit year | 2024 |
YY | 2-digit year | 24 |
MMMM | Full month name | June |
MMM | Short month name | Jun |
MM | Month (zero-padded) | 06 |
M | Month | 6 |
dddd | Full weekday name | Saturday |
ddd | Short weekday name | Sat |
DD | Day (zero-padded) | 15 |
D | Day | 15 |
HH | 24-hour (zero-padded) | 10 |
H | 24-hour | 10 |
hh | 12-hour (zero-padded) | 10 |
h | 12-hour | 10 |
mm | Minutes (zero-padded) | 30 |
m | Minutes | 30 |
ss | Seconds (zero-padded) | 45 |
s | Seconds | 45 |
A | AM/PM | AM |
a | am/pm | am |
Custom Adapters
The adapter pattern decouples date operations from the underlying library. When you call adapter.format(), the request flows through the provided adapter to its underlying date library:
Create custom adapters for different date libraries (date-fns, luxon, dayjs):
The isValid and isNullish methods are type predicates. This enables TypeScript to narrow types after validation:
const date = adapter.date(input)
if (!adapter.isNullish(date) && adapter.isValid(date)) {
// TypeScript knows `date` is Date here
adapter.format(date, 'fullDate')
}Architecture
useDate is a thin plugin around a DateAdapter. The default is V0PlainDateAdapter (a JavaScript Date). Pass V0DateAdapter for Temporal, or any other DateAdapter subclass. It resolves the active locale (from useLocale when present, otherwise its own option) and pushes it plus the derived firstDayOfWeek onto the adapter; all date math is delegated.
Reactivity
The date context provides minimal reactivity, with the adapter being a static instance.
| Property | Reactive | Notes |
|---|---|---|
locale | Computed from useLocale if available | |
adapter | Static adapter instance |
Examples
The following example builds a complete, interactive date surface from adapter calls alone — no DatePicker component required.
Recipes
Locale Integration
When useLocale is available, useDate automatically syncs with the selected locale:
import { createApp } from 'vue'
import { V0DateAdapter } from '@vuetify/v0/date'
import { createLocalePlugin, createDatePlugin } from '@vuetify/v0'
const app = createApp(App)
// Install locale plugin first
app.use(
createLocalePlugin({
default: 'en',
messages: {
en: { /* ... */ },
de: { /* ... */ },
}
})
)
// Date plugin will auto-sync with locale
app.use(
createDatePlugin({
adapter: new V0DateAdapter(),
locales: {
en: 'en-US', // Map short codes to Intl locales
de: 'de-DE',
}
})
)When switching locales via useLocale, the date adapter automatically updates its formatting locale.
Calendars
V0DateAdapter takes a calendar identifier (persian, hebrew, islamic-umalqura, …). Years, months, days, arithmetic and formatting follow that calendar, so a Hebrew leap year returns 13 entries from getMonthArray. ISO strings and Date values stay Gregorian on the way in and out.
app.use(
createDatePlugin({
adapter: new V0DateAdapter('fa-IR', { calendar: 'persian' }),
})
)Years, months, days, and arithmetic come from Temporal. Formatting comes from Intl.DateTimeFormat with an explicit calendar. Until V8 implements calendar duration math, any calendar other than iso8601 is computed with @js-temporal/polyfill. Node 26 and Chrome ship Temporal, and their non-ISO add and subtract still throw. The iso8601 path keeps the runtime Temporal. Without the option the adapter uses iso8601 and formats in Gregorian, even for locales whose Intl default is another calendar, such as fa-IR.
FAQ
The parse() method’s format parameter is ignored. Both built-in adapters delegate to date(), which accepts ISO 8601 strings. For custom format parsing, use a library like date-fns or luxon with a custom adapter.
Date formatting can cause hydration mismatches in SSR applications because the server and client environments may produce different formatted output. Two effects are at play:
adapter.date()is environment-dependent by design. In the browser it returns the current time. On the server it returns the epoch (1970-01-01) so a render does not depend on the request clock.V0PlainDateAdapteruses a JavaScriptDate.V0DateAdapterusesTemporal.Now.plainDateTimeISO(). This is intentional, to prevent hydration mismatches — if an SSR app needs the current time, passDate.now()explicitly.Intl.DateTimeFormatuses the system timezone. Server environments (often UTC) and client browsers (the user’s local timezone) produce different formatted strings.
Pick whichever fits your setup:
Nuxt/SSR: Wrap formatted dates in
<ClientOnly>:vue<template> <ClientOnly> <span>{{ adapter.format(date, 'fullDate') }}</span> </ClientOnly> </template>Vue SSR: Defer formatting until after hydration:
vue<script setup lang="ts"> import { useDate } from '@vuetify/v0' import { shallowRef, onMounted, computed } from 'vue' const { adapter } = useDate() const isMounted = shallowRef(false) const date = adapter.date('2024-06-15T10:30:00') onMounted(() => { isMounted.value = true }) const formatted = computed(() => isMounted.value ? adapter.format(date, 'fullDate') : date?.toString() )) </script>Server timezone: Set
TZ=UTCenvironment variable on your server for consistent baseline.
No — construct the adapter (and the plugin) fresh per request instead of at module scope:
// ❌ Don't: one adapter instance shared by every request for the server's lifetime
export const datePlugin = createDatePlugin({ adapter: new V0DateAdapter() })// ✅ Do: a fresh adapter per request
export function createRequestPlugins () {
return [createDatePlugin({ adapter: new V0DateAdapter() })]
}
// per request: for (const plugin of createRequestPlugins()) app.use(plugin)adapter.locale and adapter.firstDayOfWeek are mutable state kept in sync with useLocale’s selection (see Locale Integration). A shared module-scope adapter means every concurrent request’s locale sync writes to the same adapter instance — one request’s locale can leak into another’s rendered output, affecting not just formatting but calendar layout (which column a week starts in, week numbers). createDatePlugin itself is safe to install on multiple app instances — each install gets its own locale/firstDayOfWeek context — but that isolation doesn’t extend to an adapter object you construct once and pass to every install.
The adapter prefers globalThis.Temporal at runtime and falls back to @js-temporal/polyfill↗︎ when that is missing. Loading V0DateAdapter always resolves the static polyfill import, so the package stays installed even when every target has native Temporal.
Uses native Temporal when the runtime provides it; otherwise requires the @js-temporal/polyfill↗︎ optional peer. Install with
pnpm add @js-temporal/polyfill. ↩︎