Moment.js - Invalid date

I’m using Moment.js and this code works on another page and updates relativetime with the relative time since the timestamp.

<p id="relativetime"></p>
<script>
    $("#relativetime").text(moment("Sun Aug 30 2020 15:58:59 GMT+0000 (Coordinated Universal Time)").fromNow());
</script>

But, instead, on this page, it shows ‘Invalid date’. If I go into DevTools and paste in the code within the script tags, it updates with the relative time. What’s going on here? Any ideas?

Just for a test, could you remove this?

But it works on another page and works in DevTools

I have also tried using this:
https://learn.jquery.com/using-jquery-core/document-ready/
didn’t work

Oh gosh. Another one, where I make a post, carry on trying and fix it :joy:
Fixed it by make a div with a value different for everything in forEach array. Was gonna mention that in a min, but fixed it.

3 Likes