views:

272

answers:

4

Hi, Why cannot IE parse this string as a Date object.

var d = Date.parse("Fri Jun 11 04:55:12 +0000 2010"); // returns NaN

However, it works well in FireFox. I am running IE 8.

Thanks.

A: 

because of the +00000. try to add that the last

var d = Date.parse("Fri Jun 11 04:55:12 2010 +0000");
TheBrain
Yes, but does this work on all browsers and platforms ?
Nazaf
A: 

http://www.tutorialspoint.com/javascript/date_parse.htm

This will help u..

A: 

You are getting NaN value in IE 8 and its working in Firefox because, The format of the string varies with browser and operating system platform.

For example, in IE6 for Windows XP, the string is in the following format:
    Tue Dec 05 16:47:20 CDT 2006
But in Firefox for Windows XP, the string is
    Tue Dec 05 2006 16:47:20 GMT-0500

to make it compatible with both browser you will have to first check the browser in your javascript code and then accordingly give your input date string.

Jitendra
But is there a compatible common format on all browsers and platforms?
Nazaf
A: 

This may help you. I just solved a problem similar to this.

http://stackoverflow.com/questions/3243546/problem-with-javascript-date-function-in-ie-7-returns-nan

EDIT: I just realized the date on this post was june 11, not July 11. Oops.

superwhatever