判断时间间隔

  • 最长10天
const dateDiff = new Date(date[1]).getTime() - new Date(date[0]).getTime();
const dayDiff = Math.floor(dateDiff / (24 * 3600 * 1000));
if (dayDiff >= 10) {
}
  • 最长6个月
const startMonth  = new Date(date[0]).getFullYear() * 12 + new Date(date[0]).getMonth();
const endMonth  = new Date(date[1]).getFullYear() * 12 + new Date(date[1]).getMonth();
if (endMonth - startMonth > 6) {
}

let year = new Date(date[0]).getFullYear();
let month = new Date(date[0]).getMonth() + 6;
const day = new Date(date[0]).getDate();
const temp = new Date();
if (month >= 11) {
  year += 1;
  month -= 11;
  temp.setMonth(month - 1);
} else {
  temp.setMonth(month);
}
temp.setFullYear(year);
temp.setDate(day);
if (new Date(date[1]).getTime() > temp.getTime()) {
}

你可能感兴趣的:(js)