如何比较datepicker的日期?

时间:2015-08-14 03:19:25

标签: angularjs twitter-bootstrap-3 datepicker

我正在尝试将数据集过滤到日期范围。我正在使用一个日期选择器:

app.directive('datetimez', function() {
  return {
    restrict: 'A',
    require: 'ngModel',
    link: function(scope, element, attrs, ngModelCtrl) {
      element.datetimepicker({
        dateFormat: 'dd-MM-yyyy',
        language: 'en',
        pickTime: false,
        startDate: '01-11-2013', // set a minimum date
        endDate: '01-11-2030' // set a maximum date
      }).on('changeDate', function(e) {
        ngModelCtrl.$setViewValue(e.date);
        scope.$apply();
      });
    }
  };
});

日期范围过滤器如下所示:

app.filter('dateRange', function() 
{
  return function(input, dateFrom, dateTo) 
  {
    console.log('daterange filter kicksin');
    console.log(dateFrom);
    console.log(dateTo);

    return _.filter(input, function(d) {
      var testing= Date.parse(d.date) >= Date.parse(dateFrom) && Date.parse(d.date) <= Date.parse(dateTo)
      //console.log('testing filter result:',testing);
      console.log(testing);
      return testing;
    });

  }
});

唯一的问题是datepicker会吐出这种日期格式: &#34; 2015-08-03T13:15:05.158Z&#34 ;.我如何转换它,以便我可以在我的过滤器中进行比较?

plunkr:http://plnkr.co/edit/7IdepM20bH7cOol5m2LH?p=preview

0 个答案:

没有答案