js日期比较,当前时间是否在两个日期之间

var x = new Date('2015-05-25');
var y = new Date('2015-05-25');

// 1、比较两个日期大小
if (x.getTime() == y.getTime()) {
  It'll be true;
}

// 2、比较两个日期大小
// anything involving '=' should use the '+' prefix 
// it will then compare the dates' millisecond values
if (+x == +y) {
  It'll be true;
}

// 3、比较两个日期大小
if (x - y == 0) {
  It'll be true;
}

 

// 是否在两个日期之间

var beforeSpringDate, afterSpringDate;
  for (var i = 0; i < springFestivalDays.length; i++) {
    beforeSpringDate = new Date(springFestivalDays[i]);
    beforeSpringDate.setDate(beforeSpringDate.getDate() - 4);
    afterSpringDate = new Date(springFestivalDays[i]);
    afterSpringDate.setDate(afterSpringDate.getDate() + springFestivalPeriod - 1);
    if (time >= beforeSpringDate.getTime() && time <= afterSpringDate.getTime()) {
      result = true;
      break;
    }
  }

 

你可能感兴趣的:(每天进步一点点,学习永无止境,纵观千象,compare)