ValueError: astimezone() cannot be applied to a naive datetime

来源:互联网 发布:webclient 执行js 编辑:程序博客网 时间:2024/05/22 08:10

python datetime做时区转换,使用astimezone(),提示:

ValueError: astimezone() cannot be applied to a naive datetime

解决办法:

utc = pytz.utctz = pytz.timezone("Asia/Shanghai")
#先把原来时间打上utc标签,然后再时区转化time = datetime.datetime.strptime(time, fmt)origin_time = utc.localize(time)correct_time = origin_time.astimezone(tz)

0 0