I have some JSON that returns a simple date which I am placing in a DIV...
let movieDate = data.release_date;
document.getElementById('movie-date').innerHTML = movieDate;
The output is returned like this...
2021-07-14
I need to change this output to display in two different formats...
Is there a simple way to do this?
Probably the easiest is to use 3rd party library like day.js.
However can be achieved by:
const date = new Date('2021-07-14')
const monthNames = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"]
// "14 July 2021"
const sDate = `${date.getDate()} ${monthNames[date.getMonth()]} ${date.getFullYear()}`
console.log(sDate)
// 2021
console.log(date.getFullYear())