【发布时间】:2018-01-09 15:22:16
【问题描述】:
当我在有意识的datetime 实例上更改tzinfo 时,我一直得到相同的strftime 结果:
>>> from datetime import datetime
>>> import pytz
>>> fmt = '%d.%m.%Y %H:%M'
>>> now_naive = datetime.utcnow()
>>> now_naive.strftime(fmt)
'02.08.2017 11:53'
>>> now_aware = now_naive.replace(tzinfo=pytz.timezone('UTC'))
>>> now_aware_minus_3 = now_aware.replace(tzinfo=pytz.timezone('Etc/GMT-3'))
>>> now_aware.strftime(fmt)
'02.08.2017 11:53'
>>> now_aware_minus_3.strftime(fmt)
'02.08.2017 11:53'
这是为什么呢?如何在不同时区显示当前时间?
【问题讨论】:
-
这不是duplicate吗?
-
这可能会有所帮助。 - stackoverflow.com/a/18646797/5585424