我一直在尝试调试我的脚本,我无法理解这个问题:
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);
适用于Firefox,IE,Chrome,但Safari会给我一个“无效日期”错误。有什么想法吗?
答案 0 :(得分:1)
Time
和Date
的顺序错误(我猜测只是Safari):
我在Safari中对此进行了测试并且它可以正常工作(我只是在最终字符串中交换日期和时间位置):
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);
它也适用于其他浏览器,因为这是预期的。