美文网首页
Python UTC日期时间 转 本地 日期时间

Python UTC日期时间 转 本地 日期时间

作者: Hello泽泽 | 来源:发表于2020-04-02 15:36 被阅读0次

阿里云 API SDK 返回 的 UTC日期时间, 例如:2020-04-02T04:00:08Z

#!/usr/bin/env python
# author: linuxhub.cn
# coding=utf-8

import datetime

def utc_to_local(utc_date_time):
    utc_format = "%Y-%m-%dT%H:%M:%SZ"
    return datetime.datetime.strptime(utc_date_time, utc_format) + datetime.timedelta(hours=8)

utc_date_time="2020-04-02T04:00:08Z"

print u"转换前: " + str(utc_date_time)
print u"转换后: " + str(utc_to_local(utc_date_time))

# python demo.py
转换前: 2020-04-02T04:00:08Z
转换后: 2020-04-02 12:00:08

相关文章

网友评论

      本文标题:Python UTC日期时间 转 本地 日期时间

      本文链接:https://www.haomeiwen.com/subject/mtmxphtx.html