【发布时间】:2012-07-25 02:32:55
【问题描述】:
我在阿根廷,我的时间是 GMT-3 (http://wwp.greenwichmeantime.com/time-zone/south-america/argentina/)
我在玩 Pytz 时发现了一些奇怪的东西,看看:
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
这是一个错误吗?我做错了吗??
【问题讨论】:
-
提示:使用
.isoformat()将您的日期时间对象格式化为 IS 8601 字符串,而不是使用显式格式化程序。 -
@MartijnPieters - 不幸的是,这并没有带来什么。我得到了同样的结果。
-
对不起,不,我不知道这里发生了什么,只是评论一下你对strftime的使用。