IE JavaScript date parsing error

后端 未结 6 1696
南方客
南方客 2020-11-28 15:02

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

6条回答
  •  盖世英雄少女心
    2020-11-28 15:53

    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.

    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.

提交回复
热议问题