我试图找出一种方法来获取两个日期之间的时间差(以秒为单位)。
例如,以秒为单位的差异:
2013-5-11 8:37:18
2013-5-11 10:37:18
试过:
function timeDifference(laterdate, earlierdate) {
var difference = laterdate.getTime() - earlierdate.getTime();
var daysDifference = Math.floor(difference/1000/60/60/24);
difference -= daysDifference*1000*60*60*24
var hoursDifference = Math.floor(difference/1000/60/60);
difference -= hoursDifference*1000*60*60
var minutesDifference = Math.floor(difference/1000/60);
difference -= minutesDifference*1000*60
var secondsDifference = Math.floor(difference/1000);
return secondsDifference;
}
但这在Nodejs中不起作用,错误
获取时间()
找不到函数