write a profram to convert the date in string fromat to another string format.
the input date string format is like "jul 01 2014 02:43PM"
the output date string format should be like "DD/MM/YYYY HH:MM:SS"
Months = {'jan':1, 'feb':2, 'mar':3, 'apr':4, 'may':5, 'jun':6,
'jul':7, 'aug':8, 'sep':9, 'oct':10, 'nov':11, 'dec':12}
line = input()
tokens = line.split()
month = Months[tokens[0].lower()]
day = int(tokens[1])
year = int(tokens[2])
time = tokens[3]
tokens = time.split(':')
hr = int(tokens[0])
min = int(tokens[1][:2])
if len(tokens) > 2:
sec = int(tokens[2][:2])
else:
sec = 0
if tokens[-1][-2:].lower() == 'pm':
hr += 12
s = f'{day:02d}/{month:02d}/{year} {hr:02d}:{min:02d}:{sec:02d}'
print(s)
Comments
Leave a comment