【发布时间】:2011-07-20 08:34:48
【问题描述】:
当使用 pytz 在特定时区创建 datetime 对象时,我会得到不同的 UTC 偏移量,具体取决于我使用的是 datetime.datetime() 还是 datetime.datetime.now()。
now() 似乎给出了正确的时区 UTC 偏移量,datetime() 给出了一个我不认识的偏移量。
为什么它们不同? datetime() 分配的偏移量有什么意义?
这是我的代码:
import datetime
import pytz
la_paz = pytz.timezone('America/La_Paz')
a = datetime.datetime.now(la_paz)
print a, a.utcoffset()
# 2011-03-22 05:30:13-04:00 -1 day, 20:00:00
# -4 hours is the correct UTC offset for La Paz
b = datetime.datetime(2011, 03, 22, 5, 30, tzinfo=la_paz)
print b, b.utcoffset()
# 2011-03-22 05:30:00-04:33 -1 day, 19:27:00
# What is the significance of -4:33?
【问题讨论】: