javascriptangularjstimezonemomentjsangular-moment

Angular Moment : Moment Timezone has no data for America/New_York


Date received from server is in UTC timezone and I need to convert it to a particular timezone, for example : America/New_York .Following is the code for same

  <span class="bold" ng-bind="sess.date_time | amTimezone:'America/New_York' | amDateFormat:'h:mm a'"></span>

But on doing so I get the following error:

Moment Timezone has no data for America/New_York. See http://momentjs.com/timezone/docs/#/data-loading/.

But America/New_York is a known timezone to moment but still it is asking me to add the Timezone.


Solution

  • You need to load all of the following:

    On the moment-timezone home page, there are available three different distributions of moment-timezone.

    There are minified versions of each as well.

    So if you are getting "Moment Timezone has no data for America/New_York", since America/New_York is a valid TZ database identifier, then you simply haven't loaded the data for it. You are probably using moment-timezone.js without adding data to it. Either include time zone data with moment.tz.add, or (more appropriately) switch to one of the files that already includes all time zone data.

    However, do not do both. Time zone data should only be loaded once, and the moment-timezone scripts should only be loaded once. If you use either moment-timezone-with-data.js or moment-timezone-with-data-2012-2022.js, you should not be using moment-timezone.js, as that script is already included.