我在下面写了计算日期差异的函数
function dateDiff (date2, date1) {
var days = 0;
if (date2 != null && date1 != null) {
date1 = new Date(date1).getTime();
date2 = new Date(date2).getTime();
var timediff = date2 - date1;
if (!isNaN(timediff)) {
//day 86400000 = second = 1000,minute = second * 60,hour = minute * 60,day = hour * 24, to get day
days = Math.floor(timediff / 86400000);
}
}
return days > 0 ? days : 0;
};
然后我用以下参数调用了这个函数
dateDiff (new Date,'2013-09-17T00:00:00') //return 1 days
dateDiff (new Date,'2013-09-17T17:31:57.75' ) //return 0 days
value of new Date() = 'Wed Sep 18 2013 18:50:01 GMT+0530 (India Standard Time)'
这个功能在 Firefox 中可以正常工作,但在 chrome 中不能正常工作?我不明白为什么这个函数在不同的浏览器中返回不同的结果?