আগামী ৩০ অক্টোবর -২০১৭ তারিখ থেকে শুরু হচ্ছে পাঁচ মাস ব্যাপী Professional Web Design and Development with HTML,CSS,Bootstrap,PHP,MySQl, AJAX and JQUERY কোর্সের ৮৬ তম ব্যাচ। আগ্রহীদেরকে অতিসত্বর মাসুদ আলম স্যার এর সাথে যোগাযোগ করতে অনুরোধ করা যাচ্ছে। স্যার এর মোবাইল: 01722817591, Email : [email protected] কোর্সের সিলেবাস এর জন্য এখানে ক্লিক করুন ।

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

07:05:45PM

Sample Output

19:05:45
<?php

$handle = fopen ("php://stdin","r");
fscanf($handle,"%s",$time);

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

$h;
$m;
$s;

if ($pos === false) {
$h= ($time[0] == 12) ? '00' : $time[0];
$m= $time[1];
$t= intval(end($time));
$s= ($t<10) ? "0$t": $t;
}else{
$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 *