#C14520. 12-hour to 24-hour Time Converter
12-hour to 24-hour Time Converter
12-hour to 24-hour Time Converter
You are given a time in 12-hour format. Your task is to convert it into the 24-hour format.
The input is a single line string which represents a time in the format HH:MM AM/PM. The program must output the corresponding 24-hour format time string, adhering to the following rules:
- The hour component must be between 1 and 12.
- The minute component must be between 0 and 59.
- The period must be exactly
AM
orPM
(case-sensitive). - For instance, an input of 02:30 PM should produce an output of 14:30 and 12:00 AM should produce 00:00.
- If the given time format is invalid you must print
Invalid time format
.
Any extraneous spaces at the beginning or end of the input should be ignored.
The conversion follows the rules of the 12-hour clock to 24-hour clock conversion. Use LaTeX for any formulas if needed, e.g., for conversion: \(\text{if period} = \text{PM and hour} \neq 12, \text{ then } hour = hour + 12\).
inputFormat
The input is a single line read from standard input (stdin) containing a time string in the 12-hour format. For example:
12:00 AM
outputFormat
Output a single line to standard output (stdout): the converted time in 24-hour format. If the input time format is invalid, output:
Invalid time format## sample
12:00 AM
00:00