以下代码在IE中调试正常,在FF中就显示不正常,请高手看看,是哪里出了问题alert("2008-4-15 14:22:00");function GetTime(time) { var startDate = new Date(); var endDate = new Date(time.replace("-","/")); var spantime = (startDate - endDate)/1000; spantime --; var d = Math.floor(spantime / (24 * 3600)); var h = Math.floor((spantime % (24*3600))/3600); var m = Math.floor((spantime % 3600)/(60)); var s = Math.floor(spantime%60); if(d>0) { return d+"天前"; } if(h>0) { return h+"小时前"; } if(m>0) { return m+"分钟前"; } &
1 回答
明月笑刀无情
TA贡献1828条经验 获得超4个赞
好像代码不是很全
FF里的new Date()不能那样用,参数不对,把下面这一行:
var endDate = new Date(time.replace("-","/"));
改成这几行:
var s = time.split(" ");
var s1 = s[0].split("-");
var s2 = s[1].split(":");
var endDate = new Date(s1[0],s1[1]-1,s1[2],s2[0],s2[1],s2[2]);
IE7/FF2测试通过
添加回答
举报
0/150
提交
取消