from datetime import datetime , timedelta def time_handler ( target_time : str ): """ UTC世界标准时间(包含T和Z) 转 北京时间 :param target_time: :return: """ _date = datetime . strptime ( target_time , "%Y-%m-%dT%H:%M:%S.%f
def time_handler(target_time: str):
"""
UTC世界标准时间(包含T和Z) 转 北京时间
:param target_time:
:return:
"""
_date = datetime.strptime(target_time, "%Y-%m-%dT%H:%M:%S.%fZ")
local_time = _date + timedelta(hours=8)
end_time = local_time.strftime("%Y-%m-%d %H:%M:%S")
return end_time
if __name__ == '__main__':
start_time = "2020-05-08T11:16:51.000Z"
time_str = time_handler(start_time)
print(time_str) # 2020-05-08 19:16:51
【文章转自香港云服务器 http://www.1234xp.com 复制请保留原URL】