判断了几种特殊服符号的去重,并且字母无效
calendarList = [31,28,30,31,31,30,31,31,30,31,30,31]
import re
class WhickDay:
def __init__(self,date):
# super().__init__()
# #输入的年月格式为 1989/2/2 以后再补充其他的输入格式
self.date = date
self.days = 0
def CalculationDay(self,strFormat):
n = 0
try:
#首先判断输入年份是不是闰年 如果是闰年 2月加1天
#字符串分割
if int(strFormat[0]) % 4 == 0 and int(strFormat[0]) % 400 == 0:
calendarList[1] = 29
strFormat.pop(0)
while n+1 < int(strFormat[0]):
self.days += calendarList[n]
n += 1
strFormat.pop(0)
self.days = self.days + int(strFormat[0])
except:
print("输入的日期里有字母")
return self.days
def DateFormatAndOutDay(self):
dateList = re.split(r'[\s\,\!\@\#\$\%\^\&\*\(\)\.\/)]+', self.date)
self.CalculationDay(dateList)
wd = WhickDay(“1@#$%^/1##/10@@@”)
wd.DateFormatAndOutDay()
print(wd.days)