如何禁用日期范围?

时间:2019-07-30 10:10:43

标签: javascript angularjs angular-material

我需要禁用l1和l2给定的日期范围。我尝试过的方法只能禁用l1,即日期13。

var l1 = new Date("2019-07-13");
var l2 = new Date("2019-07-30");
this.flag =0;

  this.filter2 = function(date) {
    /*if(this.minDate == b){
        flag=1;
        }
        return flag;*/
        var c = date.getDate();
        for(i=l1.getDate();i<=l2.getDate();i++)
        {
            return c!=i;
            continue;
        }
        //return c!=l1.getDate() && c!=l2.getDate();
  }

2 个答案:

答案 0 :(得分:0)

您可以检查日期的ms时间戳是否在 { "documentCategoryId": [ "Error converting value \"string\" to type 'System.Guid'. Path 'documentCategoryId', line 2, position 32." ] } l1的ms时间戳之间

l2

答案 1 :(得分:0)

时间戳效果很好,但也请考虑我的评论

var l1 = new Date("2019-07-13");
var l2 = new Date("2019-07-30"); 
// l2 will result in a date like this Sun Jul 30 2019 00:00:00 so if you want for it to only work for 2019-08-01, better use directly 2018-08-01
// or set l2 to new Date("2019-07-30 23:59:59.999")

// this method will return true if the date value the function gets as a parameter is outside the given range
// for dates like: 2019-07-12 but as i specified above it will work for today's date since getTime method also consider hours, minutes, seconds and // milliseconds
this.filter2 = function(date) {
  return l1.getTime() < l2.getTime() && (date.getTime() < l1.getTime() || date.getTime() > l2.getTime())
}

console.log(filter2(new Date())) //in today's case given the mentions above it will return true
console.log(filter2(new Date('2019-07-15'))) // false
console.log(filter2(new Date('2019-07-12'))) // true