时间格式统一
def data2digit(text):
if '年' in text:
year = text.split('年')[0]
month = text.split('年')[1].split('月')[0]
day = text.split('月')[1].split('日')[0]
elif '月' in text:
year = 0
month = text.split('月')[0]
day = text.split('月')[1].split('日')[0]
else:
year = 0
month = 0
day = text.split('日')[0]
newyear = 0
newmonth = 0
newday = 0
year = int(year)
month = int(month)
day = int(day)
if year == 0:
newyear = year
else:
newyear = year
if month <= 9:
newmonth = '0'+str(month)
else:
newmonth = month
if day <= 9:
newday = '0'+str(day)
else:
newday = day
if newyear == 0:
newdate = str(newmonth) + str(newday)
elif newmonth == 0:
newdate = str(newday)
else:
newdate = str(newyear) + str(newmonth) + str(newday)
if 'None' in newdate:
print('原数据:', text)
print('转换后:', newdate)
print('请自行修改')
# print(newdate)
return newdate
#判断日期格式并选择转换格式方式输出
data1 = '2月8日'
y1 = data1[0]
if y1.isdigit():
date1 = data2digit(data1)
else:
date1 = chinese2digit(data1)
print(date1)