user1150331
user1150331

Reputation: 178

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

Upvotes: 1

Views: 166

Answers (2)

Zhonk
Zhonk

Reputation: 634

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.

Upvotes: 1

Aamir Shahzad
Aamir Shahzad

Reputation: 6834

workingfiddel

Testing on IE, Firefox and Chrome.

var d = new Date("16 Jan 2014 10:56:24 am PST");
console.log(d);

good luck!

Upvotes: 0

Related Questions