Skip to content

Commit

Permalink
js: properly format time
Browse files Browse the repository at this point in the history
  • Loading branch information
gorenburg committed Jan 10, 2025
1 parent 9bff22c commit 45d07e4
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
type DateStyle = Intl.DateTimeFormatOptions['dateStyle']

export function formatDate(date: string, dateStyle: DateStyle = 'medium', locales = 'en'): string {
const dateToFormat = new Date(date)
const dateFormatter = new Intl.DateTimeFormat(locales, { dateStyle })
return dateFormatter.format(dateToFormat)
export function formatDate(date: string, dateStyle: DateStyle = 'long', locales = 'en-US') {
const dateToFormat = new Date(date.replace(/ /, 'T').replace(/ /, ''))
return new Intl.DateTimeFormat(locales, { dateStyle }).format(dateToFormat)
}

0 comments on commit 45d07e4

Please sign in to comment.