下面是我在2.7中尝试的python代码
def date_format_change():
DB_date = "03-NOV-2016"
split2 = DB_date.split('-')
print split2[0]
M_date = float(round(split2[0]),2)
print M_date
Month = {'JAN': '1', 'FEB': '2', 'MAR': '3', 'APR': '4', 'MAY': '5','JUN': '6', 'JUL': '7', 'AUG': '8', 'SEP': '9',
'OCT': '10', 'NOV': '11', 'DEC': '12'}
DB_Month = str(split2[1])
print DB_Month
M_Month = int(Month[DB_Month])
M_year = split2(2)
print M_year
Changed_format = str(M_Month) +"/"+ str(M_date)+"/"+ str(M_year)
print Changed_format
date_format_change()
但我说的是错误的:
Traceback (most recent call last):
File "C:/Users/aannam002c/workspace/Website/Century/views.py", line 17, in <module>
03
date_format_change()
File "C:/Users/aannam002c/workspace/Website/Century/views.py", line 5, in date_format_change
M_date = float(round(split2[0]),2)
TypeError: a float is required
Process finished with exit code 1
有人能帮忙吗?你知道吗
float()接受一个参数,您给出了两个参数,而且日期的float类型看起来不太好。int就可以了。另外,
round
接受一个数字,split2[0]
是一个字符串。你知道吗这可能就是你想要的:
它返回:
以下是解决您问题的简单方法:
希望这有帮助。你知道吗
我特别喜欢dateparser软件包。它使解析日期的第一步变得轻而易举。只要向它抛出一个有点像日期的字符串,或者对时间的引用,它就会为您将它转换成
datetime
。你知道吗安装后:
相关问题 更多 >
编程相关推荐