0
當我使用http://angular-ui.github.io/bootstrap/如何使用角UI日期選擇器
給我在我的頁面和按鈕的點擊兩條datepickers的AngularUI日期選擇需要驗證發現的時間差,如果這兩個值之間的時間差大於12個月。 我還沒有找到任何可以使用的方法。
當我使用http://angular-ui.github.io/bootstrap/如何使用角UI日期選擇器
給我在我的頁面和按鈕的點擊兩條datepickers的AngularUI日期選擇需要驗證發現的時間差,如果這兩個值之間的時間差大於12個月。 我還沒有找到任何可以使用的方法。
請看這裏http://plnkr.co/edit/CeZrzGqD90cvaMLER6R5?p=preview 我已經做了消費,當年有365天。
angular.module('plunker', ['ui.bootstrap']);
var DatepickerDemoCtrl = function($scope) {
$scope.open = function($event, opened) {
$event.preventDefault();
$event.stopPropagation();
$scope[opened] = true;
};
$scope.dateOptions = {
formatYear: 'yy',
startingDay: 1
};
function yearDiff(first, second) {
if(second && first){
return (second-first)/(1000*60*60*24*365);
}
else
{
return 0;
}
}
$scope.$watch('start', function(i){
$scope.diff = yearDiff($scope.start, $scope.end)
console.log($scope.diff);
});
$scope.$watch('end', function(i){
$scope.diff = yearDiff($scope.start, $scope.end)
console.log($scope.diff);
});
$scope.formats = ['dd-MMMM-yyyy', 'yyyy/MM/dd', 'dd.MM.yyyy', 'shortDate'];
$scope.format = $scope.formats[0];
};
感謝您的代碼!當我在我的代碼中實現相同的時候,第二個投擲會給出一個NaN! – lrd123 2014-09-03 13:01:18
@ lrd123我更新了代碼,請參閱answear – sylwester 2014-09-03 13:07:55
這種方式奏效!我的問題是我的日期是一個字符串。所以我做了一個新的日期(mystring),然後跟着你的代碼。謝謝 – lrd123 2014-09-03 14:45:42