PHP Professional এবং Zend Certified PHP Engineer (ZCPE ) Course এ সীমিত সংখ্যক আসন বাকি আছে। আগ্রহীদেরকে অতিসত্বর মাসুদ আলম স্যার এর সাথে যোগাযোগ করার জন্য অনুরোধ করা যাচ্ছে। স্যার এর মোবাইল নম্বর : ০১৭২২ ৮১ ৭৫ ৯১

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;


I am PHP problem solver at Hackerrank. I am preparing myself for PHP zend certification exam with Masud Alam sir.
I have completed few websites using LARAVEL, also have experience on WORDPRESS.

Leave a Reply

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