datetime module

from datetime import datetime

timeIn12HourFormat = '5:30 PM'

dateTime = datetime.strptime(timeIn12HourFormat, '%I:%M %p')
timeIn24HourFormat = dateTime.strftime('%H:%M')

print(timeIn24HourFormat)

Leave a Comment

Your email address will not be published. Required fields are marked *