Angular JS:日期范围选择器选择前一天的日期

问题描述 投票:3回答:2

我正在使用角度日期范围选择器来选择一个日期,这是我的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 

我在这里做错了什么?有帮助吗?

angularjs datepicker daterangepicker
2个回答
1
投票

您可以通过以下方式将时区添加到日期,

var d = new Date('yourDate');
d.setMinutes( d.getMinutes() + d.getTimezoneOffset() );

'd' should be the correct date

Or您也可以像'Your Date'.toISOString()

一样进行检查

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>
© www.soinside.com 2019 - 2024. All rights reserved.