下面是蟒蛇代碼,我在2.7試過,如何從「03 - 11月-2016」的日期格式更改爲2016年11月3日
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
任何人都可以幫忙嗎?
'split2'保持字符串 - 你需要'INT( 「03」)'將文本轉換爲數字。 – furas