12-Hour to 24-Hour Time Conversion - aloalgo

12-Hour to 24-Hour Time Conversion

Easy

You are given a time in 12-hour AM/PM format. Your task is to convert this time into 24-hour format.

The 12-hour format string will be in the format "HH:MM AM" or "HH:MM PM". The 24-hour format should be in "HH:MM" format.

Here's how the conversion works:

  • 12:00 AM (midnight) becomes 00:00
  • 12:01 AM to 12:59 AM becomes 00:01 to 00:59
  • 01:00 AM to 11:59 AM remains 01:00 to 11:59
  • 12:00 PM (noon) remains 12:00
  • 01:00 PM to 11:59 PM becomes 13:00 to 23:59

Example 1

Input
"12:00 AM"
Output
"00:00"
Explanation:

Midnight (12:00 AM) in 12-hour format is 00:00 in 24-hour format.

Example 2

Input
"02:30 PM"
Output
"14:30"
Explanation:

2 PM in 12-hour format is 14:00 in 24-hour format. So, 02:30 PM becomes 14:30.

Example 3

Input
"05:05 AM"
Output
"05:05"
Explanation:

AM times (excluding 12:xx AM) generally remain the same in 24-hour format. 05:05 AM is 05:05.

Loading...
Input
"12:00 AM"
Output
"00:00"

Hello! I am your ✨ AI assistant. I can provide you hints, explanations, give feedback on your code, and more. Just ask me anything related to the problem you're working on!