python实现格林威治时间到北京时间的转化

# ===UTC2BJS
def UTC2BJS(UTC):
    UTC_format = "%Y-%m-%dT%H:%M:%S.%fZ"
    BJS_format = "%Y-%m-%d %H:%M:%S"
    UTC = datetime.strptime(UTC,UTC_format)
    #格林威治时间+8小时变为北京时间
    BJS = UTC + timedelta(hours=8)
    BJS = BJS.strftime(BJS_format)
    return BJS

# ===BJS2UTC
def BJS2UTC(BJS):
    UTC_format = "%Y-%m-%dT%H:%M:%S.%fZ"
    BJS_format = "%Y-%m-%d %H:%M:%S"
    BJS = datetime.strptime(BJS,BJS_format)
    #北京时间-8小时变为格林威治时间
    UTC = BJS - timedelta(hours=8)
    UTC = UTC.strftime(UTC_format)
    return UTC

 

posted @ 2020-11-05 17:41  醒日是归时  阅读(1554)  评论(0编辑  收藏  举报