把字符串格式的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'
posted @ 2022-12-09 17:19  坚强的小蚂蚁  阅读(172)  评论(0编辑  收藏  举报