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