Link to home
Create AccountLog in
Avatar of Bruce Gust
Bruce GustFlag 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.

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?
SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
check the following, different timezone set with moment but 23s difference between a and b because the object passed is a Date which have the timezone in
and second example don't have
User generated image



User generated image


ASKER CERTIFIED SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Avatar of Bruce Gust

ASKER

Thank you,boys! I'm going to let my team lead determine how he wants to handle this, but your counsel gives me what I need to sound intelligent when I talk to him.

Thanks!
You're welcome!

Good luck!