我有这个js代码:
toolFilters.filter('dateAccordingToTimeZone', function($filter) {
// Gets the number of milliseconds pass from 1970 and convert it to time according to given timezone, currently
// supported “Asia/Jerusalem” and “America/Los_Angeles”
return function(milliSeconds, timeZoneId) {
if (milliSeconds == 0) {
return "";
}
return moment().tz(milliSeconds, timeZoneId).format('MMM d, y H:mm:ss z'); // 5am PDT
};
})
和这个html
<script src="bower_components/moment/moment.js"></script>
在通过凉亭安装后
但是我收到了这个错误:
VM9216:1 Uncaught TypeError: moment(...).tz is not a function
at eval (eval at <anonymous> (filters.js:31), <anonymous>:1:10)
at filters.js:31
at fn (eval at compile (angular.js:15551), <anonymous>:4:485)
at regularInterceptedExpression (angular.js:16658)
at expressionInputsWatch (angular.js:16579)
我该如何解决这个问题?
因为我基于official doc
没有&#34;要求&#34;因为我使用原生的js
。力矩()格式();答案 0 :(得分:3)
Moment Timezone是一个单独的模块,除了需要时还需要安装。 请参阅document以了解如何安装它。
演示没有 tz
模块:
moment().tz();
&#13;
<script src="https://momentjs.com/downloads/moment.js"></script>
</script>
&#13;
使用 tz
模块演示:
moment().tz();
&#13;
<script src="https://momentjs.com/downloads/moment.js"></script>
<script src="https://momentjs.com/downloads/moment-timezone.min.js"></script>
&#13;