Reputation: 107
Not sure why the following is returning false
. The format specified in the second argument is exactly what I've specified while initializing a Bootstrap Datetimepicker.
moment('Fri 5 Jan, 2018 - 05:00 PM', 'ddd d MMM, YYYY - hh:mm A').isValid()
I am trying to convert datetime in the first argument to YYYY-MM-DD HH:mm
format, but moment
keeps returning an Invalid Date error.
Upvotes: 0
Views: 1378
Reputation: 160
You need to use timezone. Without time zone you might get wrong result.
var dateFormat = 'ddd D MMM, YYYY - hh:mm A';
moment(moment("Fri 5 Jan, 2018 - 05:00 PM",'Asia/kolkata').format(dateFormat),dateFormat).isValid();
Upvotes: 0
Reputation: 713
According to the documentation you should use a capital D for the day digit (5 Jan), whereas you now have a lowercase d.
moment('Fri 5 Jan, 2018 - 05:00 PM', 'ddd D MMM, YYYY - hh:mm A').isValid();
Upvotes: 5