我有一个很大的搜索字段,用户可以在其中输入任何文本,它会搜索它。
现在我需要将 dob 添加到我的搜索中。我没有添加带有 dob 选择器的新文本框。我只是希望用户能够输入多种格式的 dob,它会弄清楚的。
IE 用户可以使用以下任意组合进行搜索:
- 1970 年 8 月 25 日
- 25-08-1970
- 1970/08/25
- 1970-08-25
我的程序必须找出每个的 dmy。
有没有更好的办法?
def parse(dob):
for d in dob.split(" "):
# find the dob
if len(d) == 10:
# its a dob
if d[0:4].isdigit() # this is the year
year = d[0:4]
month = d[5:7]
day = d[8:10]
elif d[6:10].isdigit() # this is the year
day = d[0:2]
month = d[3:5]
year= d[6:10]