admin管理员组文章数量:1313121
I have this js code:
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
};
})
and this html
<script src="bower_ponents/moment/moment.js"></script>
after installing via bower
but i get this error:
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 pile (angular.js:15551), <anonymous>:4:485)
at regularInterceptedExpression (angular.js:16658)
at expressionInputsWatch (angular.js:16579)
how can i fix this?
as I based on the official doc
just without the "require" as I use native js
moment().format();I have this js code:
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
};
})
and this html
<script src="bower_ponents/moment/moment.js"></script>
after installing via bower
but i get this error:
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 pile (angular.js:15551), <anonymous>:4:485)
at regularInterceptedExpression (angular.js:16658)
at expressionInputsWatch (angular.js:16579)
how can i fix this?
as I based on the official doc
just without the "require" as I use native js
moment().format(); Share Improve this question edited Jun 20, 2020 at 9:12 CommunityBot 11 silver badge asked Apr 29, 2018 at 14:48 Elad BendaElad Benda 36.7k92 gold badges283 silver badges493 bronze badges 1- 1 I followed the docs. that's why i'm asking – Elad Benda Commented Apr 29, 2018 at 14:54
1 Answer
Reset to default 6Moment Timezone is a separate module, that needs to be installed in addition to moment. See the document to see how to install it.
Demo without tz
module:
moment().tz();
<script src="https://momentjs./downloads/moment.js"></script>
</script>
Demo with tz
module:
moment().tz();
<script src="https://momentjs./downloads/moment.js"></script>
<script src="https://momentjs./downloads/moment-timezone.min.js"></script>
本文标签: javascriptTypeError moment()tz is not a functionStack Overflow
版权声明:本文标题:javascript - TypeError: moment(...).tz is not a function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741922985a2405116.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论