python 時間格式轉換


python 時間格式轉換

python xxxx年xx月xx日轉換成日期 xxxx-xx-xx


import time
def datetrans(text):
    dates = time.strptime(text, "%Y年%m月%d日")
    return time.strftime("%Y-%m-%d", dates)


publish_Time = "2018年10月10日"
array = time.strptime(publish_Time, u"%Y年%m月%d日")
try:
    publishTime = time.strftime("%Y-%m-%d", array)
except Exception, e:
    print e
print publishTime

python 時間轉換 年月日時分秒只保留年月日


"""2021-05-18 15:13:40 只保留年月日"""
date="2021-05-18 15:13:40"
dates = time.strptime(date, "%Y-%m-%d %H:%M:%S")
dates = time.strftime("%Y-%m-%d", dates)
print(dates)

博客推薦:https://www.liaoxuefeng.com/wiki/1016959663602400/1017648783851616


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM