视图和模型中的日期与POST中的日期不同


Diffrent date in view and model than in POST

所以我使用moment.js来获取我的本地日期。这是有效的。在视图和角模型中,我有我的本地时间。

但是当我发送POST到我的php脚本,日期返回到GMT时间(检查在请求有效载荷)。可以肯定的是,就在请求之前,我正在将数据从模型写入控制台。这是我的本地约会!

我不知道哪里出错了

按注释…共享指令代码

csapp.directive('csDateToIso', function () {
    var linkFunction = function (scope, element, attrs, ngModelCtrl) {
        ngModelCtrl.$parsers.push(function (datepickerValue) {
            return moment(datepickerValue).format('YYYY-MM-DD');
        });
    };
    return {
        restrict: 'A',
        require: 'ngModel',
        link: linkFunction
    };
});

它从所选日期中删除时区部分…不过要注意@jpaugh的建议