Python JAVA接口UTC 时间 '2018-08-06T10:00:00.000Z' 格式转化为本地时间

Python JAVA接口UTC 时间 '2018-08-06T10:00:00.000Z' 格式转化为本地时间

方法1

import datetime
origin_date_str= "2019-07-26T08:20:54Z"
utc_date = datetime.datetime.strptime(origin_date_str, "%Y-%m-%dT%H:%M:%SZ")
local_date = utc_date + datetime.timedelta(hours=8)
local_date_str = datetime.datetime.strftime(local_date ,'%Y-%m-%d %H:%M:%S')
print(local_date_str )    # 2019-07-26 16:20:54



 

方法2

import datetime
origin_date_str= "2019-07-26T08:20:54.000Z"
utc_date = datetime.datetime.strptime(origin_date_str, "%Y-%m-%dT%H:%M:%S.%fZ")
local_date = utc_date + datetime.timedelta(hours=8)
local_date_str = datetime.datetime.strftime(local_date ,'%Y-%m-%d %H:%M:%S')
print(local_date_str )    # 2019-07-26 16:20:54

 

posted @ 2022-01-25 18:05  树下水月  阅读(14)  评论(0编辑  收藏  举报