Search code examples
javascriptcross-browserdate-conversion

javascript date() not work with IE


Converting this format date

"2014, 6, 2"

not work with IE
Example:

 var date = "2014, 6, 2";
 console.log(new Date(date));

IE return invalid date any idea please


Solution

  • Parsing Date is not implemented the same across browsers.

    Either you (pre)parse/format it by yourself or maybe you can try something like http://momentjs.com/

    More detailed - EcmaScript5 Spec states:

    ECMAScript defines a string interchange format for date-times based upon a simplification of the ISO 8601 Extended Format. The format is as follows: YYYY-MM-DDTHH:mm:ss.sssZ

    [...]

    The function first attempts to parse the format of the String according to the rules called out in Time String Format (15.9.1.15) [above paragraph]. If the String does not conform to that format the function may fall back to any implementation-specific heuristics or implementation-specific date formats.