Avatar of Bruce Gust
Bruce Gust
Flag for United States of America

asked on 

How do you change the default timezone in moment.js?

I've got some bizarre timeframes showing up in my app and I'm pretty certain it's coming from a default timezone discrepancy in "moment.js."

If you head out to the docs, you find this:

To change the default time zone, use moment.tz.setDefault with a valid time zone.

To reset the default time zone to local, use moment.tz.setDefault with no arguments.


I can find "moment.tz.setDefault," but it's not followed by "America/New York" or anything that intuitive. Instead, I get this:

      moment.tz.setDefault = function(name) {
            if (major < 2 || (major === 2 && minor < 9)) {
                  logError('Moment Timezone setDefault() requires Moment.js >= 2.9.0. You are using Moment.js ' + moment.version + '.');
            moment.defaultZone = name ? getZone(name) : null;
            return moment;

...and other such pieces of syntax.

I want to believe that this should be fairly easy.

What am I missing?

Avatar of undefined
Last Comment
David Favor

8/22/2022 - Mon