sql-snippets / src /lib /utils.ts
cfahlgren1's picture
cfahlgren1 HF staff
init
db39944
raw
history blame contribute delete
367 Bytes
type DateStyle = Intl.DateTimeFormatOptions['dateStyle']
export function formatDate(date: string, dateStyle: DateStyle = 'medium', locales = 'en') {
// Safari is mad about dashes in the date
const dateToFormat = new Date(date.replaceAll('-', '/'))
const dateFormatter = new Intl.DateTimeFormat(locales, { dateStyle })
return dateFormatter.format(dateToFormat)
}