我正在使用角度日期范围选择器来选择一个日期,这是我的html的样子:
<input date-range-picker ng-model="model" options="{singleDatePicker: true}"
class="form-control date-picker" type="text"/>
现在,当我选择一个日期时,日历会弹出,它显然会选择日期,但是当它发送到后端时,它实际上是前一天的日期。即,如果我选择28-02-2020
,它将发送27-02-2020
。另外,我只希望datepicker仅发送日期,目前它发送的日期是这样的:
2020-02-27T19:00:00.000Z
我在这里做错了什么?有帮助吗?
答案 0 :(得分:4)
使用AngularJS,日期选择器需要将ng-model-options
时区设置为UTC:
<input type="date" ng-model="pickedDate" ng-model-options="{timezone: 'utc'}">
有关更多信息,请参见
<script src="//unpkg.com/angular/angular.js"></script>
<body ng-app>
<h1>Hello Plunker!</h1>
<input type="date" ng-model="pickedDate" ng-model-options="{timezone: 'utc'}">
<br>
pickedDate={{pickedDate}}
</body>
答案 1 :(得分:1)
您可以通过以下方式将时区添加到日期
var d = new Date('yourDate');
d.setMinutes( d.getMinutes() + d.getTimezoneOffset() );
'd' should be the correct date
或
您也可以像'Your Date'.toISOString()