If I have a date that looks like this?
Sun, Nov 14, 2021 04:52:00PM
How can I convert this into unix time?
I did new Date(‘Sun, Nov 14, 2021 04:52:00PM’)
and .getTime() to it however i get returned NaN?
Is there a way of doing this moment or js?
>Solution :
With momentjs you can use the ddd, MMM DD, YYYY HH:mm:ss pattern:
const d = "Sun, Nov 14, 2021 04:52:00PM"
const parsed = moment('Sun, Nov 14, 2021 04:52:00PM',
'ddd, MMM DD, YYYY HH:mm:ss').toDate()
console.log(parsed)
console.log('unix:', parsed.getTime())
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js" integrity="sha512-qTXRIMyZIFb8iQcfjXWCO8+M5Tbc38Qi5WzdPOYZHIlZpzBHG3L3by84BBBOiRGiEb7KKtAOAs5qYdUiZiQNNQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>