Convert 12 Hour Time to 24 Hour Time using Python

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

Cancel reply

Your email address will not be published.