Javascript Date String returns invalid Date

date, javascript

Solution

use moment.js:

var date = moment("13.02.2015 12:55", "DD.MM.YYYY HH.mm").toDate();

Update 2022-05-28:

Meanwhile the project status of `moment.js` has changed. Therefore I strongly suggest to read https://momentjs.com/docs/#/-project-status/ and observe the recommendations.

Problem

I am trying to convert a date string into a date object within javascript. My date has the following format: ``` "13.02.2015 12:55" ``` My current approach was: ``` var d = new Date("13.02.2015 12:55"); ``` But this didnt work and always returns invalid date. If I enter a date as "12.02.2015 12:55" it works in chrome but not in firefox. I guess this is because he thinks the first part is the month, but in germany this is not the case. How can I get this to work?

Original source

Related problems