Skip to content

DateFormatterConfig

Configuration options for formatting Date objects.

// 1. ISO format
const cfgIso: DateFormatterConfig = { method: 'ISO' };
console.log(cfgIso.method); // "ISO"
// 2. Epoch timestamp
const cfgEpoch: DateFormatterConfig = { method: 'epoch' };
console.log(cfgEpoch.method); // "epoch"
// 3. Custom locale formatting: verbose French date
const cfgCustom: DateFormatterConfig = {
method: 'custom',
locales: 'fr-FR',
options: { year: 'numeric', month: 'long', day: 'numeric' }
};
const formatter = createDateFormatter(cfgCustom.locales, cfgCustom.options);
console.log(formatter.format(new Date())); // e.g., "26 juillet 2025"

optional locales: string | string[]

BCP 47 language tag(s) for locale-sensitive formatting when method is 'custom'. Defaults to the host environment’s locale.


method: "custom" | "ISO" | "epoch"

The formatting method to apply:

  • 'ISO' → Returns the result of date.toISOString().
  • 'epoch' → Returns the numeric timestamp (milliseconds since Unix epoch).
  • 'custom'→ Uses Intl.DateTimeFormat with the specified locales and options.

optional options: DateTimeFormatOptions

Formatting options (e.g., year, month, day, hour, etc.) for Intl.DateTimeFormat when method === 'custom'.

https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat#parameters