Time Converting
Hey Guys,I Made This Function To Convert Time From 12hours to 24hours And Vice Versa: def TimeConverter(time,mode): if mode not in ("12to24","24to12"): raise ValueError(f"Unknown Mode: '{mode}'") from datetime import datetime if mode == "12to24": time_converted = datetime.strptime(time, "%I:%M:%S %p") string_time = datetime.strftime(time_converted, "%H:%M:%S") return string_time else: time_converted = datetime.strptime(time, "%H:%M:%S") string_time = datetime.strftime(time_converted,"%I:%M:%S %p") return string_time It Works Properly But The Problem Is That When The User Enters Time Like ("12:35 AM") Or ("18:42:33:21.6") An Error Occurs As I Wrote In My Code That The Format Of The Time Should Be:(Hours:Minutes:Seconds) How Can I Make The Code Suitable For All Formats?