Time Conversion Algorithm

Time Conversion, Algorithm

Given a time in -hour AM/PM format, convert it to military (-hour) time.

Note: Midnight is on a -hour clock, and on a -hour clock. Noon is on a -hour clock, and on a -hour clock.

Input Format

A single string containing a time in -hour clock format (i.e.: or ), where and .

Output Format

Convert and print the given time in -hour format, where .

Sample Input


Sample Output


$handle = fopen ("php://stdin","r");

$time= explode(":", $time);
$pos = strpos(end($time), 'PM');


if ($pos === false) {
$h= ($time[0] == 12) ? '00' : $time[0];
$m= $time[1];
$t= intval(end($time));
$s= ($t<10) ? "0$t": $t;
$h= ($time[0] == 12) ? 12 : 12+$time[0];
$m= $time[1];
$t= intval(end($time));
$s= ($t<10) ? "0$t": $t;

echo $h.':'.$m.':'.$s;


Leave a Reply

Your email address will not be published. Required fields are marked *