Time Conversion
Note: Midnight is 12:00:00AM on a 12-hour clock, and 00:00:00 on a 24-hour clock. Noon is 12:00:00PM on a 12-hour clock, and 12:00:00 on a 24-hour clock.
Function Description
Complete the timeConversion function in the editor below. It should return a new string representing the input time in 24 hour format.
timeConversion has the following parameter(s):
- s: a string representing time in hour format
Input Format
A single string containing a time in -hour clock format (i.e.: or ), where and .
Constraints
- All input times are valid
Output Format
Convert and print the given time in -hour format, where .
Sample Input 0
07:05:45PM
Sample Output 0
19:05:45
php
<?php
/*
* Complete the timeConversion function below.
*/
function timeConversion($s) {
/*
* Write your code here.
*/
return date('H:i:s', strtotime($s));
}
$fptr = fopen(getenv("OUTPUT_PATH"), "w");
$__fp = fopen("php://stdin", "r");
fscanf($__fp, "%[^\n]", $s);
$result = timeConversion($s);
fwrite($fptr, $result . "\n");
fclose($__fp);
fclose($fptr);
Hello, Im finding it difficult to understand how this works although it works for me, I will be glad to get a mail of the explanation.
ReplyDeletereturn date('H:i:s', strtotime($s));