24-Hour to 12-Hour Time Conversion - aloalgo

24-Hour to 12-Hour Time Conversion

Easy

You are given a time in 24-hour format (e.g., "14:30"), convert it to 12-hour format with AM/PM (e.g., "2:30 PM"). The input time will always be a valid string in "HH:MM" format.

Example 1

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

14 hours is 2 PM. Minutes remain 30. Result is 2:30 PM.

Example 2

Input
"09:05"
Output
"9:05 AM"
Explanation:

9 hours is 9 AM. Minutes remain 05, formatted as two digits. Result is 9:05 AM.

Example 3

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

00 hours (midnight) converts to 12 AM. Minutes remain 00. Result is 12:00 AM.

Loading...
Input
"14:30"
Output
"2:30 PM"

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!