1

I was reading the MDN Date constructor documentation today and noticed that MDN itself doesn't recommend you use the Date constructor or the Date.parse() method to parse from date-strings.

date-fns itself requires the date-string to be a Date.

moment.js can do it, but I read several articles recommending not to use it.

So the question is, is there an alternative to the Date constructor?

  • I recommend that you choose a library and get used to it. That will be the most important factor for a library - not how fast it parses dates, but how comfortable you are using it. Unless you **really** need to take performance into consideration (99% of the time you won't), then just choose one that you think has a nice api and get used to it. – TKoL Aug 04 '20 at 14:52
  • Normally I use date-fns for parsing dates. However today I encountered a problem with the JS Date constructor when parsing a date. That's what motivated the question. – Thiago Feliciano Aug 04 '20 at 14:55
  • 1
    You've read what's up at [this answer](https://stackoverflow.com/a/2587398/1563833) right? – Wyck Aug 04 '20 at 14:55
  • There's nothing wrong with the Date itself (except that it hasn't been brought into the 21st century), it's only the built–in parser that has issues. There are many libraries for parsing, you can write one in an afternoon, it's fairly trivial and repetitious. The key is that it should rely on being told the format, which is a missing feature from the ECMAScript parser. If only the TC39 would include decent parsing and formatting functions, life would be simple… For a light, simple parser and formatter, consider [Fecha.js](https://github.com/taylorhakes/fecha). – RobG Aug 04 '20 at 23:09

0 Answers0