我使用下面的代码创建了一个不知道的日期时间,我需要在 UTC 中使用它,因为时间在“美国/东部”。我想先让日期时间知道 EST,然后再转换为 UTC。
import datetime
import pytz
from pytz import timezone
dt = "8/8/2013 4:05:03 PM"
dt = datetime.datetime.strptime(dt,"%m/%d/%Y %I:%M:%S %p")
unaware_est = dt.strftime("%Y-%m-%dT%H:%M:%S")
localtz = timezone('US/Eastern')
utc = localtz.localize(unaware_est)
错误信息:
Traceback (most recent call last):
File "/home/ubuntu/workspace/druidry-codebase/services/xignite/test.py", line 120, in <module>
quote_time = localtz.localize(quote_time)
File "/usr/local/lib/python2.7/dist-packages/pytz-2013b-py2.7.egg/pytz/tzinfo.py", line 303, in localize
if dt.tzinfo is not None:
AttributeError: 'str' object has no attribute 'tzinfo'