【问题标题】:amDateFormat is clobbering amTimezone in AngularJSamDateFormat 正在破坏 AngularJS 中的 amTimezone
【发布时间】:2019-02-14 22:41:13
【问题描述】:

我的代码如下,安装了angular-moment包:

<td data-ng-bind="'2019-02-04T13:42:06.927+00:00' | amTimezone:'America/Halifax' | amDateFormat: 'MM/DD/YYYY hh:mm A'"></td>

该代码输出:“02/04/2019 01:42 PM”

当我在没有 amDateFormat 过滤器的情况下运行上述代码时,我得到: “2019 年 2 月 4 日星期一 09:42:06 GMT-0400”

所以我知道每个过滤器都在工作,但是在对 angular-moment.js 文件进行一些调试之后,preprocessDate 将其称为破坏我的时区信息的内容。

.filter('amDateFormat', ['moment', 'amMoment', 'angularMomentConfig', function (moment, amMoment, angularMomentConfig) {
                function amDateFormatFilter(value, format) {
                    if (isUndefinedOrNull(value)) {
                        return '';
                    }

                    var date = amMoment.preprocessDate(value);
                    if (!date.isValid()) {
                        return '';
                    }

                    return date.format(format);
                }

                amDateFormatFilter.$stateful = angularMomentConfig.statefulFilters;

                return amDateFormatFilter;
            }])

我在 angular-moment.js 文件的 angularMomentConfig 中将预处理设置为 null,但它正在从 moment.js 运行 createUTC() 作为预处理器函数。

我不知道该函数是如何被调用的,或者这是否是导致我的问题的原因,但我们将不胜感激任何帮助。

【问题讨论】:

    标签: angularjs momentjs angular-moment


    【解决方案1】:

    我想通了。 我们在核心模块中设置了一个我没有看过的预处理器。

    .constant('angularMomentConfig', {
        preprocess: moment.utc
      })
    

    删除它使其能够正常工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-14
      • 2015-06-09
      • 1970-01-01
      • 1970-01-01
      • 2021-08-07
      • 2018-01-16
      • 1970-01-01
      • 2011-09-05
      相关资源
      最近更新 更多