0

Im trying to parse a timestamp string to date object, but it keeps telling me its an invalid date.

Mon Jun 21 10:14:54 CEST 2021

Where new Date('Mon Jun 21 10:14:54 CEST 2021') return an invalid date error. Date.parse and toDate also return the same error. I used http://natty.joestelmach.com/try.jsp# to test if an online parser was able to recognize it and it did. What can be wrong here?

  • That is an extremely random accumulation of values. Usually the day-month-year parts are somewhere close to each other, not with the year at the very end. The timezone is usually the last thing in the string. `Date` simply can't magically understand anything and everything you throw at it. – deceze Jun 21 '21 at 09:50
  • Natty, which you explicitly link to, is a project dedicated to that topic: *"Natty is a natural language date parser written in Java. Given a date expression, natty will apply standard language recognition and translation techniques to produce a list of corresponding dates…".* The default Javascript `Date` implementation simply isn't _that_ flexible. – deceze Jun 21 '21 at 09:51

0 Answers0