moment / moment-timezone

Timezone support for moment.js
momentjs.com/timezone
MIT License
3.82k stars 835 forks source link

Can not set default timezone #1079

Closed rzvdaniel closed 10 months ago

rzvdaniel commented 10 months ago

Environment

{ date: "Thu Nov 02 2023 12:37:34 GMT+0100 (Central European Standard Time)", intlZone: "Europe/Madrid", moment: "2.18.1", momentTz: "0.5.43" }

No other frameworks are being used other than moment.js and moment-timezone.js.

Issue description

Setting the timezone using moment.tz.setDefault("America/Los_Angeles") does not have effect on the retrieved date later on.

moment.tz.setDefault("America/Los_Angeles");
var date = moment.utc('2023-01-20T00:00:00').format();

Doing the same using moment.utc(date).tz("America/Los_Angeles")works as expected.

var date = moment.utc('2023-01-20T00:00:00').tz("America/Los_Angeles")

Here is a Fiddle that demonstrate it: https://jsfiddle.net/0sLyzvpb/7/

Is moment.tz.setDefault() having an issue?

rzvdaniel commented 10 months ago

Hi, guys!

Do no bother anymore with thicket, closing it.

I missed the fact that the project is in maintenance mode, so no point in chasing you any longer :P.

Good luck! Razvan

gilmoreorless commented 10 months ago

moment.utc() overrides the default to explicitly set the time zone as UTC. Calling just moment(dateString).format() should use the zone from moment.tz.setDefault() correctly.