troubleshooting Question

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

Avatar of Bruce Gust
Bruce GustFlag for United States of America asked on
JavaScriptNode.js
6 Comments3 Solutions231 ViewsLast Modified:
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.

moment.tz.setDefault("America/New_York");
To reset the default time zone to local, use moment.tz.setDefault with no arguments.

moment.tz.setDefault();


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?
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 3 Answers and 6 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 3 Answers and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros