使用angular和jQuery datepicker计算天差

在角度,我试图使用jQuery datepicker计算两个选定日期之间的天数。 它只使用我正在使用的函数返回null。

但是我不太确定它是函数还是在angular中使用datepicker。看起来问题是函数但是当我和jQuery一起使用它时它会工作。

我的function:

$scope.dayDiff = function(firstDate,secondDate){ $scope.dayDifference = parseInt(Math.round((secondDate - firstDate) / (1000 * 60 * 60 * 24)));; } 

其余的: http : //jsfiddle.net/1mzgLywe/5/

提前致谢!

这是工作小提琴请检查, 链接到小提琴

创建一个函数,让dateString传递给new Date()

 $scope.formatString = function(format) { var day = parseInt(format.substring(0,2)); var month = parseInt(format.substring(3,5)); var year = parseInt(format.substring(6,10)); var date = new Date(year, month-1, day); return date; } 

修改dayDiff函数如下,

 $scope.dayDiff = function(firstDate,secondDate){ var date2 = new Date($scope.formatString(secondDate)); var date1 = new Date($scope.formatString(firstDate)); var timeDiff = Math.abs(date2.getTime() - date1.getTime()); var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24)); alert(diffDays); } 

角度矩可以解决问题! ……和(非常)其他更多。

使用amDifferencefilter:

获取两个日期之间的差异(以毫秒为单位)。 参数是日期,单位和usePrecision。 日期默认为当前日期。 例:

 Difference: {{ dateFrom | amDifference : dateTo : 'days' }} days