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

The date received from the server is in the UTC time zone, and I need to convert it to a specific time zone, for example: America/New_York . By default, this is the code for the same

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

But at the same time 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 famous time zone for moment , but still it asks me to add a time zone.

+6
source share
1 answer

You need to download all of the following:

  • moment
  • time zone
  • time zone data for an instant-time
  • angular -moment

On the tz database home page for the version mentioned on the website.

moment-timezone-with-data-2012-2022.js contains the same tz data, but is truncated only from 2012 to 2022. This is a much smaller data file and is sufficient for most browser-side applications.

/ li>

There are also miniature versions of each of them.

So, if you get "Moment Timezone has no data for America/New_York" , since America/New_York is a valid TZ database identifier, you simply did not upload data for it. You are probably using moment-timezone.js without adding data to it. Either include time zone data using moment.tz.add , or (in a more appropriate way) switch to one of the files, which already includes all time zone data.

However, do not do both. Time zone data should be downloaded only once, and moment and time scenarios should be downloaded only once. If you use either moment-timezone-with-data.js or moment-timezone-with-data-2012-2022.js , you should not use moment-timezone.js since this script is already included.

+30
source

All Articles