I have a problem outputting the date in Javascript.
I want to output 2021-03-02T00:00:00+00:00
to March 2, 2021
export function parseDate(dateString) {
const [date, time] = dateString.split(' ')
return new Date(`${date}T${time}.000Z`) // Z = UTC
}
export function formatDate(dateString) {
if (!dateString) return ''
const date = parseDate(dateString)
return date.toLocaleString('en', {
year: 'numeric',
month: 'long',
day: 'numeric'
})
}
console.log(formatDate(data?.createdAt))