Format a Date or string for display. Locale-aware, no heavy libraries.
export function formatDate(
date: Date | string | number,
options: Intl.DateTimeFormatOptions = {}
): string {
const d = date instanceof Date ? date : new Date(date);
if (Number.isNaN(d.getTime())) return '';
return new Intl.DateTimeFormat('en-US', {
year: 'numeric',
month: 'short',
day: 'numeric',
...options,
}).format(d);
}Accepts Date, ISO string, or timestamp.
Pass a second argument to Intl options, e.g. { month: 'long', weekday: 'short' }. Use different locale as first argument to DateTimeFormat if needed.