1

Have an issue with Date parsing by given pattern. Problem is only in IE. In Chrome it works fine.

Sample code is:

var dateValue = moment("04/05/2015 00:00:00", "DD/MM/YYYY HH:mm:ss").toDate();

Also here is fiddle for this snippet: https://jsfiddle.net/Alex13ss/rsxmx7bc/1/

Try to open it in IE and look at output. Inside result you will see [date] Invalid Date

Tried a lot of options and googled a lot. Still have no result. Also it is not necessary to use momentjs for me if you have an idea.

One hint can be after you will try to evaluate dateValue = moment("04/05/2015 00:00:00", "DD/MM/YYYY HH:mm:ss").toDate(); in IE console.

Please keep in mind that there can be a lot of formats depending on locale, but data will always match string pattern for parsing.

Thanks in advance for any suggestions/solutions! :)

P.S. Close question is this but not the same, please be attentive! :) Can be a good hint, but not an answer.

Community
  • 1
  • 1
Alex
  • 35
  • 7
  • 1
    Possible duplicate of [Why does Chrome Dev Tool show a dates \_\_proto\_\_ as Invalid Date?](http://stackoverflow.com/questions/9725299/why-does-chrome-dev-tool-show-a-dates-proto-as-invalid-date) – Andreas Feb 22 '17 at 15:10
  • 1
    nothing wrong with the code (fiddle). I got the expected result in IE. maybe something's wrong with your PC. – m87 Feb 22 '17 at 15:11
  • I tried `console.log(new Date());` and I still get `Invalid Date` inside the Date object. other than that though it works fine. – Shai Feb 22 '17 at 15:21
  • Please try to evaluate `dateValue = moment("04/05/2015 00:00:00", "DD/MM/YYYY HH:mm:ss").toDate();` in IE console. It can be a hint. – Alex Feb 22 '17 at 15:31
  • Writing `new Date()` in the console creates the same issue. It's not a problem with `moment` but with IE and `Date`s in general. – Shai Feb 22 '17 at 15:59
  • @Shai and do you have any ideas how to solve it on my app lvl? – Alex Feb 22 '17 at 16:10
  • The important question is, besides the fact that it says `[date] Invalid Date`, do you have any other problems with the resulting Date object? As I see from some testing, the Date object you get behaves as it should. – Shai Feb 22 '17 at 16:23
  • @Shai the problem is that in representative control it doubles date segmentally. It can't parse Date properly and gets it's toString value. Again, in Chrome it works fine. But your comment pushed me to think about some another way of Date usage in app js part. – Alex Feb 22 '17 at 18:32
  • I can't run the "fiddle" at all in IE 10. Far better to post code here as a runnable snippet. You can include moment.js from a CDN. – RobG Feb 22 '17 at 23:08

0 Answers0