TypeError: moment(...).tz is not a function
12,054
Moment 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.com/downloads/moment.js"></script>
</script>
Demo with tz
module:
moment().tz();
<script src="https://momentjs.com/downloads/moment.js"></script>
<script src="https://momentjs.com/downloads/moment-timezone.min.js"></script>
Related videos on Youtube
Comments
-
Elad Benda almost 2 years
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_components/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 compile (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();-
Elad Benda about 6 yearsI followed the docs. that's why i'm asking
-
-
Philipp Beck about 6 yearsOkay the you need to import it in addition to
moment
, will edit my answer. -
Elad Benda about 6 yearsIt fails parsing my tz format even though it was supposed to support according to documentation stackoverflow.com/questions/50088484/…
-
Kevz about 2 yearsRunning code snippet gives a moment(...).tz is not a function error in console log