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

30,234

You need to load all of the following:

  • moment
  • moment-timezone
  • time zone data for moment-timezone
  • angular-moment

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

  • moment-timezone.js is just the script. It contains no time zone data. If you use this distribution, it's expected that you will pull in your own time zone data, either by moment.tz.add, or moment.tz.load, as described in the docs.

  • moment-timezone-with-data.js includes all known time zone data from the tz database, for the version mentioned on the web site.

  • moment-timezone-with-data-2012-2022.js includes the same tz data, but is truncated to just years 2012 through 2022. This is a much smaller data file, and is sufficient for the majority of browser-side applications.

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.

Share:
30,234

Related videos on Youtube

Aman Gupta
Author by

Aman Gupta

Updated on March 24, 2021

Comments

  • Aman Gupta
    Aman Gupta about 3 years

    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.

  • Aman Gupta
    Aman Gupta over 8 years
    In the backend(express), I did not 'require' js for timezone data and it is working fine. May be for client side we need to get this data explicitly as you mentioned, will let you know if this works.
  • Aman Gupta
    Aman Gupta over 8 years
    Great!! It worked. Was getting "Moment Timezone 0.4.0 was already loaded without any data" error then carefully re-read your answer and the last two last lines solved the mystery :)
  • crthompson
    crthompson almost 8 years
    Thank you for your comment @AmanGupta. Dont use both! (timezone and data) scripts, is the lesson learned here.
  • Joshua Dyck
    Joshua Dyck over 6 years
    As per the moment docs, "In Node.js, all the data is preloaded. No additional code is needed for loading data." This is all you need to get started on the server: var moment = require('moment-timezone'); moment().tz("America/Los_Angeles").format();
  • Matt Johnson-Pint
    Matt Johnson-Pint over 6 years
    @JoshuaDyck Yes, but the question was about the browser, not Node.
  • Joshua Dyck
    Joshua Dyck over 6 years
    In my experience, the npm module method works in browser and node. However, you would have to consider the amount of data being loaded if you are concerned with performance. Also, when using JS frameworks and webpack I prefer to use npm modules as opposed to using script tags where possible to load vendor libraries.