Mar*_*Mar 4 jquery datepicker angularjs
在角度,我试图使用jQuery datepicker计算两个选定日期之间的天数.它只使用我正在使用的函数返回null.
但是我不太确定它是函数还是在angular中使用datepicker.看起来问题是函数,但是当我和jQuery一起使用它时它会起作用.
我的功能:
$scope.dayDiff = function(firstDate,secondDate){
$scope.dayDifference = parseInt(Math.round((secondDate - firstDate) / (1000 * 60 * 60 * 24)));;
}
Run Code Online (Sandbox Code Playgroud)
其余的: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;
}
Run Code Online (Sandbox Code Playgroud)
修改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);
}
Run Code Online (Sandbox Code Playgroud)
角度矩可以解决问题!......和(非常)其他更多.
使用amDifference过滤器:
获取两个日期之间的差异(以毫秒为单位).参数是日期,单位和usePrecision.日期默认为当前日期.例:
<span>Difference: {{ dateFrom | amDifference : dateTo : 'days' }} days</span>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
20173 次 |
| 最近记录: |