AngularJS UI datePicker总是有一天关闭
问题描述:
在应用程序中使用AngularJS UI datePicker,在表单上有三个日期输入。无论选择和保存的日期如何,这一天总是提前一天。我已经尝试了日期格式的每一个组合,并搜索这个主题的每一个论坛帖子,但没有任何作品。我可以更改我的代码以便在选择日期时获得正确的日期?AngularJS UI datePicker总是有一天关闭
JS
configAppControllers.controller('deadLineDatePickerCtrl', ['$scope', '$timeout',
function ($scope, $timeout) {
$scope.today = function() {
$scope.dt = new Date();
};
$scope.today();
$scope.clear = function() {
$scope.dt = null;
};
// Disable weekend selection
$scope.disabled = function (date, mode) {
// return (mode === 'day' && (date.getDay() === 0 || date.getDay() === 6));
};
$scope.toggleMin = function() {
$scope.minDate = $scope.minDate ? null : new Date();
};
$scope.toggleMin();
$scope.open = function ($event, id) {
$event.preventDefault();
$event.stopPropagation();
$scope.opened = true;
$timeout(function() {
$("#" + id).focus();
});
};
$scope.dateOptions = {
formatYear: 'yy',
startingDay: 1
};
$scope.initDate = new Date('2012/03/21');
$scope.formats = ['dd-MMMM-yyyy', 'yyyy/MM/dd', 'dd.MM.yyyy', 'shortDate'];
$scope.format = $scope.formats[3];
}
]);
HTML
<div class="input-group deadline">
<input name="deadLine" id="deadLine" type="text" class="form-control"
data-ng-required="true"
datepicker-popup="{{format}}"
data-ng-model="programDetails.deadline"
is-open="opened"
min-date="programDetails.startDate"
datepicker-options="dateOptions"
date-disabled="disabled(date, mode)"
close-text="Close"
show-button-bar="false"/>
<span class="input-group-btn">
<button type="button" class="btn btn-default" data-ng-click="open($event)"><i
class="fa fa-calendar"></i></button>
</span>
答
如果任何人有日期是一天下来有日期选择器插件,这个同样的问题,我能够通过使用getTimezoneOffset来解决这个()方法如下:
user.deadline = formatDate(new Date(deadlineDate.getTime() + deadlineDate.getTimezoneOffset() * 60000));
解决了问题!
这对我来说,非常感谢。 – 2017-03-06 12:05:33