format
API index · Input types and conventions · Installation
format(value, pattern, options?) → string
Render selected fields for display or fixed text output. locale defaults to en-US and controls month, weekday, and day-period labels through the host's Intl data. Numeric output uses ASCII digits.
Instant requires timeZone. ZonedDateTime uses its own zone unless overridden; plain values reject zone options. XX and XXX output Z at zero offset and discard historical offset seconds. SSS displays milliseconds without rounding the input's finer precision.
import { format } from '@frantss/temporal-fns';
const date = Temporal.PlainDate.from('2026-10-23');
format(date, 'EEEE, MMMM d, yyyy'); // => 'Friday, October 23, 2026'
format(Temporal.PlainYearMonth.from('2026-10'), 'yyyy-MM'); // => '2026-10'
format(Temporal.PlainMonthDay.from('02-29'), 'MM/dd'); // => '02/29'
format(date, 'MMMM', { locale: 'es-UY' }); // => 'octubre'
format(Temporal.Instant.from('2026-10-24T01:00Z'), 'yyyy-MM-dd HH:mm XXX', {
timeZone: 'America/Montevideo',
}); // => '2026-10-23 22:00 -03:00'
format(date, 'HH:mm'); // throws RangeErrorRelated: parse, formatRelative, formatDuration.
Behaviors: FMT-001: Numeric tokens retain their distinct meanings; FMT-005: Partial values expose only the information they contain; FMT-008: Instant formatting requires a viewing zone; FMT-012: Locale selects grammatical text labels; FMT-015: Offset tokens intentionally discard historical offset seconds; FMT-006: Missing fields cannot be invented by formatting.