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
Add a ment  | 

1 Answer 1

Reset to default 6

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./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