把字符串格式的UTC时间,转为北京时间
from datetime import datetime, timedelta
push_time = '2022-03-23T08:40:10.895Z'
push_time1 = datetime.strptime(push_time[0:-5], "%Y-%m-%dT%H:%M:%S") + timedelta(hours=8)
print(push_time1)
push_time2 = datetime.strptime(push_time, "%Y-%m-%dT%H:%M:%S.%fZ") + timedelta(hours=8)
print(push_time2)
输出为
2022-03-23 16:40:10
2022-03-23 16:40:10.895000
如果只想显示为某天
>>> time3=push_time1.strftime('%F')
>>> time3
'2022-03-23'
努力生活,融于自然