← Back to challenges

24-Hour Time

PythonHardstringsnumbersdates

Instructions

Write a function that receives the time in 12-hour AM/PM format and returns a string representation of the time in military (24-hour) format.

Examples

convert_time(“07:05:45PM”) ➞ “19:05:45”

convert_time(“12:40:22AM”) ➞ “00:40:22”

convert_time(“12:45:54PM”) ➞ “12:45:54”

Notes

  • Midnight is 12:00:00AM on a 12-hour clock, and 00:00:00 on a 24-hour clock.
  • Noon is 12:00:00PM on a 12-hour clock, and 12:00:00 on a 24-hour clock.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.