0

In javascript, I can not do new Date("10Apr14") in IE, it will give back invalid Date, but the same command works fine in chrome.

Anyone knows how to make it work for all browers?

Thanks

user3527917
  • 327
  • 2
  • 10
  • 22
  • 1
    Read the [docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) – James Jul 21 '14 at 20:56
  • Possible duplicate ? http://stackoverflow.com/questions/2182246/javascript-dates-in-ie-nan-firefox-chrome-ok – kemicofa ghost Jul 21 '14 at 20:56

1 Answers1

1

The problem is you are using a 2 digit year (see year in RFC 2822). You should use:

new Date('10Apr2014'); // April 10, 2014

Or better yet, don't pass a string into the Date constructor because that can be error prone and is generally less common. It is much better to use it like this:

new Date(2014, 3, 10); // April 10, 2014

See this: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date

Community
  • 1
  • 1
pseudosavant
  • 7,056
  • 2
  • 36
  • 41