js 对日期加减

function getDate(days) {
  var now = new Date(),
    newDate = new Date(now.getTime() - 86400000 * days),
    yyyy = newDate.getFullYear(),
    mm = (newDate.getMonth() + 1) < 9 ? '0' + (newDate.getMonth() + 1) : newDate.getMonth() + 1,
    dd = newDate.getDate() < 9 ? '0' + newDate.getDate() : newDate.getDate();
  return (yyyy + '-' + mm + '-' + dd + ' 00:00');
}

原文地址:https://www.cnblogs.com/Brittany-yan/p/5147434.html