intlDateTime

intlDateTime(value, options?) formats a date-like value as localized date/time text. Use this for values you already have in JS and want the same output as <intl-datetime>.

It uses the same option model as: Intl.DateTimeFormat and uses the same runtime locale resolution as components.

Native output context: HTML `.

Input shape

value can be:

ts
1import { intlDateTime } from '@beforesemicolon/intl'2 3intlDateTime('2026-01-01T10:00:00Z')4intlDateTime(1704067200000)5intlDateTime(new Date('2026-01-01T10:00:00Z'))

Signature

ts
1function intlDateTime(2  value: string | number | Date,3  options?: Intl.DateTimeFormatOptions & {4    locale?: string5    scope?: IntlRuntime6  }7): string

Invalid date input returns ''.

Important options

OptionTypeDefaultEffect
localestringruntime/DOM localeOne-off locale override
scopeIntlRuntimegetIntl()Scope override (when using nested runtimes)
dateStylefull | long | medium | shortundefinedPreset date formatting
timeStylefull | long | medium | shortundefinedPreset time formatting
calendarstringruntime defaultOverride calendar
numberingSystemstringruntime defaultOverride digit system
timeZonestringruntime defaultIANA zone like UTC
timeZoneNamelong | shortundefinedShow timezone label
hour12booleanruntime defaultForce 12h clock
hourCycleh11 | h12 | h23 | h24runtime defaultAlternative hour formatting
weekdaynarrow | short | longundefinedDay name output
yearnumeric | 2-digitundefinedYear part
monthnumeric | 2-digit | narrow | short | longundefinedMonth part
daynumeric | 2-digitundefinedDay part
hournumeric | 2-digitundefinedHour part
minutenumeric | 2-digitundefinedMinute part
secondnumeric | 2-digitundefinedSecond part
fractionalSecondDigits1 | 2 | 3undefinedFractional seconds
eranarrow | short | longundefinedEra label

Examples

Presets

ts
1intlDateTime(Date.now(), { dateStyle: 'short' })2intlDateTime(Date.now(), { timeStyle: 'medium' })3intlDateTime(Date.now(), { dateStyle: 'long', timeStyle: 'short' })

Field-level formatting

ts
1intlDateTime('2026-01-01T10:00:00Z', {2    weekday: 'long',3    year: 'numeric',4    month: 'long',5    day: '2-digit',6    hour: '2-digit',7    minute: '2-digit',8    timeZone: 'America/Sao_Paulo',9})

Locale and timezone variants

ts
1intlDateTime('2026-01-01T10:00:00Z', {2    locale: 'en-US',3    timeZone: 'UTC',4    timeStyle: 'short',5})6 7intlDateTime('2026-01-01T10:00:00Z', {8    locale: 'fr-FR',9    timeZone: 'Europe/Paris',10    timeZoneName: 'short',11})

Scope integration

ts
1import { createIntl, intlDateTime } from '@beforesemicolon/intl'2 3const scoped = createIntl({ locale: 'en-GB', messages: {} })4 5intlDateTime('2026-01-01T10:00:00Z', { scope: scoped })

Empty output rules

ts
1intlDateTime('bad-date-string') // ''2intlDateTime(NaN as unknown as number) // ''

See also

edit this doc