Js 获取日期相差的天数
//两个日期('yyyy-MM-dd') function dateDiff(date1, date2) { var type1 = typeof date1, type2 = typeof date2; if (type1 == 'string') date1 = stringToTime(date1); else if (date1.getTime) date1 = date1.getTime(); if (type2 == 'string') date2 = stringToTime(date2); else if (date2.getTime) date2 = date2.getTime(); return (date2 - date1) / (1000 * 60 * 60 * 24); //结果是秒 }
//和现在的日期比较 function GetNowDiff(s) { var s1 = new Date(s.replace(/-/g, "/")); var s2 = new Date(); var days = s1.getTime() - s2.getTime(); return parseInt(days / (1000 * 60 * 60 * 24)); }