X Enterprises
Composables

useXafDateFormat

Locale-aware date formatting composable — long / short / numeric / relative presets, UTC pinning for SSR stability, follows useXafLocale.

useXafDateFormat

Locale-aware date formatting for the review-site family. Auto-imported. Follows the active useXafLocale() locale by default and can pin to UTC so server and client render identical strings for YYYY-MM-DD inputs. Used internally by <XAFDateDisplay> and <XAFLastUpdated>.

Usage

const { format, formatRelative, parse, resolvedLocale } = useXafDateFormat({
  locale: 'en-GB', // optional — defaults to the active useXafLocale value or 'en-US'
  utc: true,       // optional — pin YYYY-MM-DD inputs to UTC midnight (SSR stability)
})

format('2026-02-15')              // "15 February 2026" (long, default)
format('2026-02-15', 'short')     // "15 Feb 2026"
format('2026-02-15', 'numeric')   // "15/02/2026"
formatRelative('2026-02-13')      // "2 days ago"
parse('2026-02-15')               // Date | null

Invalid or empty input returns the raw input string from format / formatRelative, and null from parse — safe to call with untrusted CMS data.

Options

KeyTypeDefaultDescription
localestringactive useXafLocale value or 'en-US'BCP-47 locale.
utcbooleanfalsePin YYYY-MM-DD strings to UTC midnight so rendered dates are stable across server/client timezones. Recommended for ISO date-only inputs.

Returns

KeyTypeDescription
format(iso: string | undefined, preset?: 'long' | 'short' | 'numeric' | 'relative') => stringFormat an ISO date string. Returns the raw input on failure.
formatRelative(iso: string | undefined) => stringRelative time string (e.g. "2 days ago"). Returns the raw input on failure.
parse(iso: string) => Date | nullParse an ISO date string. null on failure.
resolvedLocaleComputedRef<string>Currently resolved locale (reactive).

AI Context

composable: useXafDateFormat
package: "@xenterprises/nuxt-x-affiliate"
use-when: >
  Formatting ISO dates in review/article templates with locale awareness
  (follows useXafLocale) and SSR stability (utc option). Powers
  <XAFDateDisplay> and <XAFLastUpdated> internally.
Copyright © 2026