CaitlinW
CaitlinW

Reputation: 205

Moment Timezone : I don't understand how default timezones work

Say it's 10:00am in my local time, America/Denver. When I set the default timezone in moment timezone:

moment.tz.setDefault("America/Chicago");

Current time objects are printed out in the correct timezone, America Chicago:

moment().toString(); // returns 11:00am

However, when I parse in a date, for example:

// exampleTime equal to 9:05am, already in America/Chicago
var parsedTime = moment(exampleTime, "HH:mm")

It seems to take the date, parse it in the local timezone ("America/Denver") and then "convert" it to America/Chicago. So, when I:

parsedTime.toString(); //prints ~10:05am

It prints out a time that is an hour ahead of what it should be.

Do I have to specify the timezone of every time I parse in? Why wouldn't it parse in the default timezone?

Upvotes: 3

Views: 2149

Answers (1)

Matt Johnson-Pint
Matt Johnson-Pint

Reputation: 241920

You're using it correctly, you're just hitting on a bug. It's already been logged in this issue, and there's a pending fix here.

Upvotes: 2

Related Questions