//+---------------------------------------------------
//| 求两个时间的天数差 日期格式为 YYYY-MM-dd
//+---------------------------------------------------
function daysBetween(DateOne,DateTwo)
{
var OneMonth = DateOne.substring(5,DateOne.lastIndexOf ('-'));
var OneDay = DateOne.substring(DateOne.length,DateOne.lastIndexOf ('-')+1);
var OneYear = DateOne.substring(0,DateOne.indexOf ('-'));
var TwoMonth = DateTwo.substring(5,DateTwo.lastIndexOf ('-'));
var TwoDay = DateTwo.substring(DateTwo.length,DateTwo.lastIndexOf ('-')+1);
var TwoYear = DateTwo.substring(0,DateTwo.indexOf ('-'));
var cha=((Date.parse(OneMonth+'/'+OneDay+'/'+OneYear)- Date.parse(TwoMonth+'/'+TwoDay+'/'+TwoYear))/86400000);
return Math.abs(cha);
}
获取两个时间的小时和分秒,统统计算出秒,然后计算出查值,再把差值转换分钟,就知道时间差了。
function diffDate(str1, str2) {
str1 = str1.replace(/-/g, "/");
str2 = str2.replace(/-/g, "/");
var d1;
var d2;
var diffday = 0;
if (str1 == "") {
d1 = new Date();
} else {
d1 = new Date(str1);
}
if (str2 == "") {
d2 = new Date();
} else {
d2 = new Date(str2);
}
diffday = Date.parse(d1) - Date.parse(d2);
diffday = diffday.toFixed(2) / 86400000 ;
return diffday;
}