我遇到了 DateDiff 函数的问题。我试图找出两个日期/时间之间的差异。我已经阅读了这篇文章(What's the best way to calculate date Difference in Javascript)并且我还查看了本教程(http://www.javascriptkit.com/javatutors/datedifference.shtml),但我似乎无法理解.
这是我试图开始工作但没有成功的原因。有人可以告诉我我在做什么以及如何简化它。似乎有点过度编码...?
//Set the two dates
var currentTime = new Date();
var month = currentTime.getMonth() + 1;
var day = currentTime.getDate();
var year = currentTime.getFullYear();
var currDate = month + "/" + day + "/" + year;
var iniremDate = "8/10/2012";
//Show the dates subtracted
document.write('DateDiff is: ' + currDate - iniremDate);
//Try this function...
function DateDiff(date1, date2) {
return date1.getTime() - date2.getTime();
}
//Print the results of DateDiff
document.write (DateDiff(iniremDate, currDate);