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