js比较时间大于6个月

//mons是比较的月数,如 2019-02-01 14:27:08 - 2019-08-01 14:27:08
function compareTime(mons,stTime,endTime){
    var st  = new Date(stTime);
    var et = new Date(endTime);
    var st6mon=new Date(st);
    st6mon.setMonth(st6mon.getMonth()+mons);
    
    if(et.getTime()>st6mon.getTime()){
      //末位时间超时起始时间6个月
    return true;
}
  return false;
//ps:可以用 if(et >(或<) st6mon),但比较if(et==st6mon)永远返回false,可能==返回的是对象地址引用,所以用getTime() }

猜你喜欢

转载自www.cnblogs.com/xiaoliu66007/p/11976814.html