Question

I am using nodejs and recently started using moment.timezone to get the timezone offset. I have the following code:

console.log(moment.tz(new Date(), 'Europe/Athens').zone()); // Prints -120

The timezone for 'Europe/Athens' is GMT+2 so i would expect getting '120' and not '-120' and thats what other timezone libraries do.

This issue caused me a serious head scratching bug. It was really easy to fix it once found the problem by just inverting the timezone offset.

Is this a bug on the specific library, or is there a different way to think of zones and offsets? Is there a standard about zone offsets?

Était-ce utile?

La solution

This is expected behavior. zone() returns the offset to UTC relative to the selected timezone.

http://momentjs.com/timezone/docs/#/how-to/mutator/

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top