gpt4 book ai didi

jquery - AngularJS UI datePicker 总是休息一天

转载 作者:行者123 更新时间:2023-12-01 04:48:00 25 4
gpt4 key购买 nike

我在应用程序上使用 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>

最佳答案

如果有人对 datePicker 插件的日期为休息日有同样的问题,我可以通过使用 getTimezoneOffset() 方法来解决这个问题,如下所示:

user.deadline = formatDate(new Date(deadlineDate.getTime() + deadlineDate.getTimezoneOffset() * 60000));

问题解决了!!

关于jquery - AngularJS UI datePicker 总是休息一天,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26143138/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com