Angular.js:输入日期显示日期-1天

Wal*_*ann 3 date angularjs

我有一个表格<input type="date">

当我在此输入中绑定数据时,它将显示日期-1天。

HTML:

<div class="input-field col s12">
    <label>Fecha Nacimiento </label>
    <input type="date" class="form-control" id="fnac" name="fnac" ng-model="unapersona.fnac">
</div>
Run Code Online (Sandbox Code Playgroud)

控制器:

$scope.cargarpersona = function(id) {
    $http.get("modelos/personas_json.php?id="+id)
    .success(function(data) {
        $scope.unapersona = eval(data);
        //... Other data
        $scope.unapersona.fnac = new Date($scope.unapersona[0]["fnac"]);
        //... Other data
    })
    .error(function(data) {
        console.log('Error: ' + data);
    });
}
Run Code Online (Sandbox Code Playgroud)

屏幕截图

Wal*_*ann 7

解决了!!我只把ng-model-options =“ {timezone'UTC'} ”输入日期

<input type="date" class="form-control" id="fnac" name="fnac" ng-model="unapersona.fnac" ng-model-options="{timezone:'UTC'}">
Run Code Online (Sandbox Code Playgroud)

https://docs.angularjs.org/api/ng/directive/ngModelOptions

感谢您的答复和时间!

  • 我自己偶然发现了这个解决方案,很高兴您也找到了它:) (2认同)