I'm trying to convert the following date I'm getting from the API:
2022-04-01T05:09:09.403Z
To the next one:
July 19, 2021
But I don't know how to do it. I've tried this so far:
const months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
for (var i = 0; i < postsResults.length; i++) {
const trimmedData = postsResults[i].last_posted_at
const finalData = trimmedData.substring(0, 10);
let monthDate = finalData.slice(5,7)
if (monthDate.includes(0)) {
monthDate = finalData.slice(6,7)
} else {
monthDate = finalData.slice(5,7)
}
result = months[monthDate]
}
Postsresults is the array that I'm fetching. I'm slicing certain characters until I get the exact letters to match the months. This doesn't work as it always returns April.