Localize dates with Vue I18n
A practical review of date localization in Vue I18n: what the d function and datetimeFormats change, where time zones and copy/paste cause trouble, and when an ISO date is the better choice.
Vue I18n can show the same date as "Oct 31, 2026" to one visitor and in a German or Japanese style to another. It does this without separate translation strings for each month name. This review explains what that formatting changes, what it leaves alone, and where it can cause problems once the text is copied, read aloud, or processed by other software.
Is Vue I18n date formatting right for your use?
For dates that people read in an interface, it is usually a good fit. Order, month names, separators and 12- or 24-hour time follow the reader's locale, and the work is done by the browser's built-in Intl.DateTimeFormat rather than by text you maintain.
The main tradeoff is that the output is display text. It is not a reliable data format. The exact string depends on the locale, the time zone, and the locale data in the runtime, so it can differ between browsers, operating systems and server environments.
Plain, unlocalized text such as an ISO 8601 date (2026-10-31) is the better choice in these cases:
- The value is stored, sent to an API, written to logs, or exported to CSV or spreadsheets.
- Another program has to parse the date.
- Users in different regions need to compare or exchange exactly the same string.
- The date appears in structured data, filenames, or anything that should sort correctly as text.
What the transformation actually changes
"Localizing" a date in Vue I18n means formatting it, not translating it. You pass a JavaScript Date (or a timestamp) to the d function, or to $d in templates. Vue I18n looks up a named format for the current locale and hands the options to Intl.DateTimeFormat. The underlying Date value does not change. Only the string generated for display does.
This is different from character-level text transformations. Nothing is reversed, mirrored or replaced with styled Unicode lookalikes. The output is ordinary text in the target locale's conventions. Some locales use non-Latin digits or insert invisible Unicode direction marks, and those characters are part of the formatted string.
Named formats are defined once per locale in the datetimeFormats option. Older Vue 2 releases of the library used the camel-cased key dateTimeFormats. Check which major version your project uses before copying examples.
import { createI18n } from 'vue-i18n'
const datetimeFormats = {
'en-US': {
short: { year: 'numeric', month: 'short', day: 'numeric' },
long: {
year: 'numeric', month: 'long', day: 'numeric',
weekday: 'long', hour: 'numeric', minute: 'numeric'
}
},
'de-DE': {
short: { year: 'numeric', month: 'short', day: 'numeric' },
long: {
year: 'numeric', month: 'long', day: 'numeric',
weekday: 'long', hour: 'numeric', minute: 'numeric'
}
}
}
export const i18n = createI18n({
legacy: false,
locale: 'en-US',
fallbackLocale: 'en-US',
datetimeFormats
})
<script setup>
import { useI18n } from 'vue-i18n'
const { d } = useI18n()
const publishedAt = new Date(Date.UTC(2026, 9, 31, 15, 0))
</script>
<template>
<time :datetime="publishedAt.toISOString()">
{{ d(publishedAt, 'long') }}
</time>
</template>
Both locales can use the same option names. The output still differs because Intl applies each locale's rules for order, wording and punctuation. In en-US, the short format above usually renders as "Oct 31, 2026", but these results were not tested here. Treat any sample output as illustrative and check it in your target browsers.
Time zones are the most common surprise
Unless a format sets a timeZone option, Intl formats in the runtime's local time zone. A date-only string such as "2026-10-31" is parsed by JavaScript as midnight UTC. In time zones behind UTC, including all of the continental US, it can therefore display as October 30. If the date should show the same day everywhere, add a timeZone option (for example 'UTC' or a specific zone such as 'America/New_York') to the named format. Another option is to construct the Date with the time zone in mind.
Server-side rendering adds a second risk. If the server and the browser use different time zones or locale data, the rendered text can differ between them and trigger hydration mismatch warnings. Setting the time zone explicitly reduces this risk.
What it does not do
- It does not parse dates typed by users. You still need separate input handling.
- The d function does not produce relative phrases such as "3 days ago." Intl.RelativeTimeFormat or a message string covers that.
- It does not convert between calendars beyond what Intl supports for the given locale and options.
- It does not fix an incorrect Date value. Errors in the input carry through to the formatted text.
Will the result stay readable after copying or sharing?
| Concern | What happens | Practical response |
| Copy/paste | The visible localized string is copied, including any invisible direction marks or locale-specific digits | Offer an ISO date where users are likely to copy values into other tools |
| Regional ambiguity | All-numeric styles such as 10/31/2026 versus 31/10/2026 can be misread when shared across regions | Prefer month names (month: 'short' or 'long') for content that travels |
| Right-to-left locales | Formatted dates in locales such as Arabic may contain Unicode bidirectional control characters that affect display order when pasted elsewhere | Test in the actual destinations. Do not assume one correct rendering applies everywhere |
| Assistive technology | Screen readers read the visible text. Month names are generally clearer than numeric-only dates, but behavior was not tested for any specific screen reader here | Wrap the date in a time element with a machine-readable datetime attribute, and check it with the assistive technology your users rely on |
| Search and structured data | The visible string is fine for readers. Crawlers and structured data expect a standard format | Put ISO 8601 values in datetime attributes and structured data |
| Editing | Localized strings are hard to edit back into a valid date | Keep the source Date or ISO value separate from the displayed text |
The time element in the example above follows this pattern: localized text for people and an ISO value for machines. Use it wherever a date is likely to be copied, indexed or processed.
Gaps in this review
No version-specific test results, browser comparisons or screen reader recordings were available for this review. Statements about rendering and assistive technology describe documented Intl and HTML behavior, not verified observations. Before relying on exact strings in a product, check the output in the browsers, server runtime and assistive technologies your users actually use.