I have moment
as a library within my project so answers with moment
are fully welcomed.
I have this date 17th May 2017, I need to convert this into a valid date object. How can I achieve this?
Both of the following returns Invalid Date
moment('17th May 2017').format(...)
new Date('17th May 2017')
What's odd is that I can use moment
to format to 'Do MMMM YYYY'
which outputs the date like the above, however I am able to do it vice versa.
Update
Please see this JSFiddle where it is working.
However, when I port it into my React app, it doesn't work as intended
const {
safe_date: date,
} = firstVideo;
console.log(
'MomentJS me!',
date,
moment(date, 'dd MMM yyyy'),
moment(date, 'dd MMM yyyy').valueOf(),
);
date
is a String
The output of my console.log
MomentJS me! 17th May 2017 ... NaN
I am not interested in the console.log of moment(date.toString(), 'dd MMM yyyy')
so I have omitted it, the odd thing is the valueOf()
is returning NaN
but returns correctly on JSFiddle.