Cannot parse month three letter month with locale en

Viewed 239

I am trying to parse a date having the form 2018 30 Oct 19:30 with Moment.js. The format for this should be YYYY dd MMM HH:mm. This is not working, and I have identified the problem to the Oct part of the string, see the below snippet:

console.log('locale: ' + moment.locale());
console.log('\'2018 31 Oct\' valid? ' + moment('2018 31 Oct', 'YYYY dd MMM').isValid());
console.log('\'2018 31\' valid? ' + moment('2018 31', 'YYYY dd').isValid());
<script src="https://momentjs.com/downloads/moment.js"></script>

Given that the locale is en (which I understand is what you get when using Moment.js without all locales) I cannot understand why 2018 31 Oct fails to parse with the format YYYY dd MMM. According to the documentation MMM is the format to use for three letter months.

What goes on here that I don't understand, and how can I solve it?

1 Answers

The dd is the Day of Week (Su Mo ... Fr Sa), while you need Day of Month (DD).

Related