js获取两个日期相差的天数

function dateDiffStr(startDateStr, endDateStr) {
  var day = 0;
  var separator = "-"; //日期分隔符
  var date1 = startDateStr.substring(0, 10).split(separator);
  var date2 = endDateStr.substring(0, 10).split(separator);
  var date11 = new Date(date1[0], date1[1]-1, date1[2]);
  var date22 = new Date(date2[0], date2[1]-1, date2[2]);
  day = parseInt(Math.abs(date22-date11) / (1000 * 60 * 60 * 24));
  return day;
}

上一篇:Makefile:26: *** missing separator. Stop.解决办法


下一篇:ASCII码值与字符的转换