开发者

Javascript "Invalid Date" error in Safari

I've been trying to debug a script of mine and I can't get my head around what's wrong with this:

var date = new Date("19871104071535".replace(
    /^(\d{4})(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/,
    '$4:$5:$6 $2/$3/$1'
));
alert(date开发者_开发知识库);

It works in Firefox, IE, Chrome but Safari gives me an "Invalid Date" error. Any ideas?


The Time and Date are in the wrong order (for just Safari I guess :):

I tested this in Safari and it works (I just swapped Date and Time position in the final string):

var date = new Date("19871104071535".replace(
    /^(\d{4})(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/,
    '$2/$3/$1 $4:$5:$6'
));
alert(date);

It will also work in the other browsers because this is what is expected.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜