Python:具有pytz时区迹象的怪异行为 [英] Python: Weird behavior with signs of pytz timezones

查看:61
本文介绍了Python:具有pytz时区迹象的怪异行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在阿根廷,我的时间是格林尼治标准时间3(http://wwp.greenwichmeantime.com/time-zone/south-america/argentina/)

I'm in Argentina, my time is GMT-3 (http://wwp.greenwichmeantime.com/time-zone/south-america/argentina/)

我在和Pytz玩耍时,发现有些奇怪的东西,看看:

I was playing with Pytz and noticed something weird, take a look:

from pytz import timezone
bsas = timezone('America/Argentina/Buenos_Aires')

gmt_plus_3 = timezone('Etc/GMT+3')
gmt_min_3 = timezone('Etc/GMT-3')

# Date and time at this momement: 2012-07-26 10:23:01

fmt = '%Y-%m-%dT%H:%M:%S'
datetime.now(bs).strftime(fmt)  #'2012-07-26T10:23:01' <-- GOOD!

datetime.now(gmt_min_3).strftime(fmt)  #'2012-07-26T16:25:21' <-- WRONG!

datetime.now(gmt_plus_3).strftime(fmt)  #'2012-07-26T10:23:01' <-- GOOD! WTF!

我希望:

GMT-3 should be 10:23:01 and gives me 16:23:01
GMT+3 should be 16:23:01 and gives me 10:23:01

这是一个错误吗?我做错了吗?

Is this a bug? Am i doing it wrong??

推荐答案

这不是bug,它是一项功能(维基百科: Tz_database ):

It is not a bug, it is a feature (Wikipedia: Tz_database):

Etc的特殊区域用于某些管理区域,尤其是代表协调世界时的"Etc/UTC".为了符合POSIX样式,以"Etc/GMT"开头的区域名称已与大多数人期望的相反,它们的符号已反转.在这种样式中,格林尼治标准时间以西的区域名称为正号,而东部地区则为负号(例如,"Etc/GMT-14"比格林尼治标准时间早14小时.)

The special area of Etc is used for some administrative zones, particularly for "Etc/UTC" which represents Coordinated Universal Time. In order to conform with the POSIX style, those zone names beginning with "Etc/GMT" have their sign reversed from what most people expect. In this style, zones west of GMT have a positive sign and those east have a negative sign in their name (e.g "Etc/GMT-14" is 14 hours ahead/east of GMT.)

这篇关于Python:具有pytz时区迹象的怪异行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆