我想把日期October012000格式轉換爲python.I'm 2000年1月10日分享我的代碼here.Please改正我的錯誤......轉換October012000格式的2000年1月10日使用Python
代碼:
date=October012000
day=date2[-6:-4]
year=date2[-4:]
month=date2[0:-6]
print year,day,month
monthDict = {'January':1, 'February':2, 'March':3, 'April':4, 'May':5, 'June':6,
'July':7, 'August':8, 'September':9, 'October':10, 'November':11, 'December':12}
month = monthDict[month]
Date=day+"/"+month+"/"+year
但我發現了以下錯誤:
輸出:
TypeError Traceback (most recent call last)
<ipython-input-23-42dbf62e7bab> in <module>()
3 #month1=str(month)
4 #day
----> 5 Date=day+"/"+month+"/"+year
TypeError: cannot concatenate 'str' and 'int' objects
嘗試在日期,月份和年份中封裝變量tr'功能。 (日期)+「/」+ str(month)+「/」+ str(year)' – gcarvelli 2014-11-22 05:31:07
'Date = str(day)+「/」+ str(month)+ 「/」+ str(year)' – nu11p01n73R 2014-11-22 05:31:18
[Python:TypeError:無法連接'str'和'int'對象]的可能重複(http://stackoverflow.com/questions/11844072/python-typeerror-cannot-concatenate- str-and-int-objects) – nu11p01n73R 2014-11-22 05:33:36