moment-timezone icon indicating copy to clipboard operation
moment-timezone copied to clipboard

.local() ignoring the default time zone

Open bladeSk opened this issue 8 years ago • 1 comments

Consider this code:

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

console.log(moment('2016-01-01T00:00:00.000Z'));
console.log(moment.utc('2016-01-01T00:00:00.000Z').local());

I would expect both lines producing the same result, but my actual local time zone is used instead of the default time zone. Output below:

moment.parseZone("2015-12-31T18:00:00.000-06:00")
moment("2016-01-01T01:00:00.000") // wrong time zone

The only workaroud for converting UTC to the default timezone, I've found, is to use moment.utc('2016-01-01T00:00:00.000Z').tz(moment().tz()), but that looks clumsy.

bladeSk avatar Sep 21 '17 13:09 bladeSk

Note that you can create a moment in local mode from UTC-based input (having the Z), which will have the same effect. moment('2016-01-01T00:00:00.000Z')

But yes, it's a bug. Or rather, something we need to consider about what "local" means with respect to changing the default time zone.

See also #258 & #247

mattjohnsonpint avatar Oct 25 '17 00:10 mattjohnsonpint