python将字符串转化为本地datetime

from pytz import timezone
from datetime import datetime
from time import mktime
import time

t1 = ‘2016-08-04T02:58:29Z’
tt1 = time.strptime(t1, “%Y-%m-%dT%H:%M:%SZ”)
dt1 = datetime.fromtimestamp(mktime(tt1))

tzchina = timezone(‘Asia/Chongqing’)
utc = timezone(‘UTC’)

dt1.replace(tzinfo=utc).astimezone(tzchina)

作者: hqiang1984

量化自我,极简主义