轉成各個國家的標準時間

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"))
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章