15 lines
374 B
TypeScript
15 lines
374 B
TypeScript
export function useDate(
|
|
iso: string | undefined,
|
|
locale: string = 'en-gb',
|
|
options: Intl.DateTimeFormatOptions = {
|
|
year: 'numeric',
|
|
month: 'long',
|
|
day: '2-digit',
|
|
},
|
|
): string {
|
|
if (!iso) return '';
|
|
const date = new Date(iso);
|
|
const parsedLocale = locale.replace('_', '-').toLowerCase();
|
|
|
|
return new Intl.DateTimeFormat(parsedLocale, options).format(date);
|
|
}
|