Python homework.
Write a function that takes as input a string that stores date and time (24-hour clock) in the following format: “MM/DD/YYYY HR:MIN:SEC” and prints the following: DD/MM/YYYY HR:MIN:SEC MM/YYYY Whether the time is a.m. or p.m. Validation of the input in the function is necessary.
CODE IN PYTHON:
def dateConversion(dateTime):
dateList = dateTime.split()
if(len(dateList)==2):
date = dateList[0].split("/")
time = dateList[1].split(":")
if(len(date)==3 and len(time)==3):
return date[1]+"/"+date[0]+"/"+date[2]+" "+dateList[1]+" "+date[0]+"/"+date[2]
return "Invalid input"
print(dateConversion("08/17/1996 12:15:22"))
INDENTATION:
OUTPUT:
Get Answers For Free
Most questions answered within 1 hours.