转成各个国家的标准时间

from datetime import datetime
import time


def utc_time(site):
    tss1 = str(datetime.utcnow()).split(".")[0]
    timeArray = time.strptime(tss1, "%Y-%m-%d %H:%M:%S")
    timeStamp = int(time.mktime(timeArray))
    if site == "us":
        us_time = timeStamp - 5 * 60 * 60
        timeArray = time.localtime(us_time)
        otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
        print(otherStyleTime)
        us_time = "".join(str(str(otherStyleTime).split(" ")[0]).split("-"))
        return us_time

    if site == "jp":  # 日本
        us_time = timeStamp + 9 * 60 * 60
        timeArray = time.localtime(us_time)
        otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
        print(otherStyleTime)
        us_time = "".join(str(str(otherStyleTime).split(" ")[0]).split("-"))
        return us_time

    if site == "fr":  # 法国
        us_time = timeStamp + 1 * 60 * 60
        timeArray = time.localtime(us_time)
        otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
        print(otherStyleTime)
        us_time = "".join(str(str(otherStyleTime).split(" ")[0]).split("-"))
        return us_time

    if site == "de":  # 德国
        us_time = timeStamp + 1 * 60 * 60
        timeArray = time.localtime(us_time)
        otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
        print(otherStyleTime)
        us_time = "".join(str(str(otherStyleTime).split(" ")[0]).split("-"))
        return us_time

    if site == "es":  # 西班牙
        us_time = timeStamp + 1 * 60 * 60
        timeArray = time.localtime(us_time)
        otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
        print(otherStyleTime)
        us_time = "".join(str(str(otherStyleTime).split(" ")[0]).split("-"))
        return us_time

    if site == "it":
        us_time = timeStamp + 1 * 60 * 60
        timeArray = time.localtime(us_time)
        otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
        print(otherStyleTime)
        us_time = "".join(str(str(otherStyleTime).split(" ")[0]).split("-"))
        return us_time

    if site == "uk":
        us_time = timeStamp
        timeArray = time.localtime(us_time)
        otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
        print(otherStyleTime)
        us_time = "".join(str(str(otherStyleTime).split(" ")[0]).split("-"))
        return us_time


print(utc_time("it"))

猜你喜欢

转载自blog.csdn.net/WBerica/article/details/86506700
今日推荐