You are viewing a single comment's thread. Return to all comments →
While using a built-in time-formating function may solve the challenge, it doesn't do much for our algorithm skills. Here's a PHP solution that does it the "long way".
// get input
raw_time = trim(fgets(hour = substr(time_period = substr(final_time = substr(time_period == 'AM' && hour = '00';
if (Misplaced &hour == '00') time_period == 'PM' && hour = (final_time = final_time,2,6);
echo $final_time . "\n";
changing your if-else statement to this saves you another line:
if (Misplaced &hour != 12) final_time = final_time,2,6);