python datetime做时区转换,使用astimezone(),提示:
ValueError: astimezone() cannot be applied to a naive datetime
解决办法:
utc = pytz.utc
tz = pytz.timezone("Asia/Shanghai")
#先把原来时间打上utc标签,然后再时区转化
time = datetime.datetime.strptime(time, fmt)
origin_time = utc.localize(time)
correct_time = origin_time.astimezone(tz)