我在我的项目中使用了角度ui datepicker(asp.net web api + angularjs).一切正常,但是当我试图将日期保存到Db时,它没有正确地将它转换为UTC格式并且导致1天(实际上是几个小时,但它也影响了一天).
例如,当我在datepicker中选择01/11/2014时:
Angularjs object:
Sat Nov 01 2014 00:00:00 GMT+0200 (FLE Standard Time)
In request:
2014-10-31T22:00:00.000Z
In asp.net api controller:
{31-Oct-14 10:00:00 PM}
Run Code Online (Sandbox Code Playgroud)
Datepicker控制器:
app.controller('DatepickerCtrl', function ($scope) {
$scope.today = function () {
$scope.dt = new Date();
};
$scope.today();
$scope.clear = function () {
$scope.dt = null;
};
$scope.open = function ($event) {
$event.preventDefault();
$event.stopPropagation();
$scope.opened = true;
};
$scope.format = 'dd/MM/yyyy';
$scope.dateOptions = {
'starting-day': 1
};
});
Run Code Online (Sandbox Code Playgroud)
hnml:
<div class="form-group inputGroupContainer" ng-controller="DatepickerCtrl">
<label …Run Code Online (Sandbox Code Playgroud) 我在Plunker上使用此自定义指令使用Angular UI引导日期选择器弹出窗口(http://plnkr.co/edit/053VJYm1MpZUiKwFTfrT?p=preview):
//Module
var userModule = angular.module("userModule",['ui.bootstrap']);
//Controller
userModule.controller("sampleController", ['$scope', function ($scope) {
$scope.minDate = new Date();
}]);
//Directive code
userModule.directive('datePicker', [function (dateFilter) {
return {
restrict: 'E',
require: 'ngModel',
scope: {
ngModel: '=',
ngReadonly: '=?',
minDate: '=?',
maxDate: '=?',
dtpRequired: '=?',
dateOptions: '=?'
},
template: '<p class="input-group">' +
'<input type="text" style="cursor:pointer" class="form-control" datepicker-popup="{{format}}"' +
'ng-model="ngModel" is-open="opened"' +
'min-date="minDate" max-date="maxDate"' +
'datepicker-options="dateOptions" date-disabled="disabled(date, mode)"' +
'ng-required="dtpRequired" close-text="Close" ng-readonly="ngReadonly" ng-click="openPopup()" />' +
'<span class="input-group-btn">' +
'<button type="button" class="btn btn-default" …Run Code Online (Sandbox Code Playgroud) html javascript angularjs angularjs-directive angular-ui-bootstrap