如何用python中的find对日期和时间切片

怎样用python对日期和时间切片并判断正误
“MM/DD/YYYY HR:MIN:SEC”,并输出如下内容:
DD/MM/YYYY
HR: MIN :SEC
MM/YYYY
时间是“AM”或“PM”
函数中需要进行验证。例如,如果用户输入“122/04/1990 13:12:12”,该字符串是无效的。考虑所有可能的错误输入,并编写代码进行处理。


'''
1582年以来的置闰规则:
普通闰年:公历年份是4的倍数,且不是100的倍数的,为闰年(如2004年、2020年等就是闰年)。
世纪闰年:公历年份是整百数的,必须是400的倍数才是闰年(如1900年不是闰年,2000年是闰年)。
平年有365天,闰年有366天(2月中多一天)

'''
examples = ["8/11/2021 15:14:28","2/29/2021 24:00:00","13/00/2021 23:00:00","10/33/2021 12:00:00","10/31/2021 12:00:00","8/31/0000 12:00:00"]

def make_date(str_date):
    month_dict={
    1:31,2:28,3:31,4:30,5:31,6:30,
    7:31,8:31,9:30,10:31,11:30,12:31,
    }
    somedate, clock=str_date.split(" ")
    month,day,year= somedate.split("/")
    hour,min,sec = clock.split(":")
    #如果是闰年2月为29天
    if int(year) and ((int(year)%4==0 and int(year)/100 !=0) or int(year)%400 == 0):
        month_dict[2] = 29

    if int(hour)>=24 or (int(min)>=60 or int(sec)>=60):
        print("字符串无效")      
    elif int(month) not in month_dict.keys():
        print("字符串无效")
    elif int(day) > month_dict[int(month)]:
        print("字符串无效")
    else:
        if int(hour)>12:
            print("{}/{}/{}".format(day,month,year))
            print("AM {}:{}:{}".format(int(hour)-12,min,sec))
            print("{}/{}".format(month,year))
        else:
            print("{}/{}/{}".format(day,month,year))
            print("PM {}:{}:{}".format(int(hour),min,sec))
            print("{}/{}".format(month,year))
        

for i in examples:
    make_date(i)