我的页面上有此JavaScript。日期数学适用于Chrome,但不适用于Firefox或Safari
function getTimeRemaining(endtime){
var t = Date.parse(endtime) Date.parse(new Date());
var seconds = Math.floor((t/1000) % 60);
var minutes = Math.floor((t/1000/60) % 60);
var hours = Math.floor((t/(1000*60*60)) % 24);
var days = Math.floor(t/(1000*60*60*24));
return {
'total': t,
'days': days,
'hours': hours,
'minutes': minutes,
'seconds': seconds
};
}
结束时间就像一个日期“2016年1月12日23时15分零零秒”
我的代码工作完全在Chrome但在Safari和Firefox返回NaN
。
欢迎使用stackoverflow :) – www139
你确定这是确切的代码吗?在Chrome和其他地方,'var t = Date.parse(endtime)Date.parse(new Date());'应该作为语法错误失败。 –