简体   繁体   中英

Inverted zone in moment.timezone

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?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM