douxiuyu2028 2015-07-09 03:44
浏览 32
已采纳

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

So I'm using moment.js to get my local date. And it's working. In the view and in the angular model I have my local time.

But when I'm sending POST to my php script, date is returning to GMT time (checked in request payload). To be sure, just before the request I'm writing date from the model to the console. And it's my local date!

I'm out of ideas what can be wrong.

  • 写回答

1条回答 默认 最新

  • duanliang2017 2015-07-09 05:18
    关注

    as per comments.. sharing the directive code

    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
        };
    });
    

    it removes the timezone part from the selected date... though be aware of @jpaugh advice

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 已知平面坐标系(非直角坐标系)内三个点的坐标,反求两坐标轴的夹角
  • ¥15 webots有问题,无响应
  • ¥15 数据量少可以用MK趋势分析吗
  • ¥15 使用VH6501干扰RTR位,CANoe上显示的错误帧不足32个就进入bus off快慢恢复,为什么?
  • ¥15 大智慧怎么编写一个选股程序
  • ¥100 python 调用 cgps 命令获取 实时位置信息
  • ¥15 两台交换机分别是trunk接口和access接口为何无法通信,通信过程是如何?
  • ¥15 C语言使用vscode编码错误
  • ¥15 用KSV5转成本时,如何不生成那笔中间凭证
  • ¥20 ensp怎么配置让PC1和PC2通讯上