I need to embed a JSON feed onto our website. I have my code working, but am struggling with the JSON date format, which is producing string values like 2024-05-08 18:00:00. Ideally, I would like to format this into something like Wednesday, May 8 6:00 PM or 05/08/2024 6:00 PM or along those lines. I am not able to edit the JSON feed directly.
My code is as follows:
<script>
document.addEventListener("DOMContentLoaded", function () {
fetch('jsonsource')
.then((response) => response.json())
.then((json) => {
console.log(json);
document.getElementById("feedtitle1").innerHTML = json[0].title;
document.getElementById("feeddesc1").innerHTML = json[0].description;
document.getElementById("feedurl1a").href = json[0].url;
document.getElementById("feedurl1b").href = json[0].url;
document.getElementById("feedurl1c").href = json[0].url;
document.getElementById("feeddate1").innerHTML = json[0].start_date;
document.getElementById("feedimage1").src = json[0].image;
})
});
</script>
<div class="FEEDcontainer">
<div class="FEEDimg"><a href="" id="feedurl1a"><img src="" id="feedimage1" class="FEEDthumb"></a></div>
<div class="FEEDtitle"><a href="" id="feedurl1b"><h1 id="feedtitle1"></h1></a></div>
<div class="FEEDdesc"> <p id="feeddesc1"></p></div>
<div class="FEEDmore"> <a href="" id="feedurl1c">Read more...</a></div>
<div class="FEEDdate"> <p id="feeddate1"></p></div>
</div>
Do you have any tips?
I’ve tried getDate and moment, but they do not work with the date string my feed produces.
SR3 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1