日期:2014-05-16 浏览次数:20391 次
function StringToDate(string) { return new Date(Date.parse(string.replace(/-/g, "/"))); } function countTimeLength(interval, date1, date2) { var objInterval = {'D' : 1000 * 60 * 60 * 24, 'H' : 1000 * 60 * 60, 'M' : 1000 * 60, 'S' : 1000, 'T' : 1}; interval = interval.toUpperCase(); var dt1 = Date.parse(StringToDate(date1)); alert(dt1); var dt2 = Date.parse(StringToDate(date2)); try { return ((dt2 - dt1) / (objInterval[interval])); } catch (e) { return e.message; } }