PHP program to convert 12HR time Format into 24HR time format.
- Nov 2, 2017
- 1 min read
Source code:
<?php
//$input = $_POST['time'];
$input = "07:05:45PM";
$arr = str_split($input); //converting string into array $n=count($arr);
if ($arr[8] == "P") { $hour = $arr[0].$arr[1]; // concatanation $hour = $hour + 12;
$arrHR = str_split($hour); //converting string into Array $arr[0] = $arrHR[0]; $arr[1] = $arrHR[1]; //placing first two places in input array
/*-----Print Final output----*/ for ($i=0; $i < 8 ; $i++) { echo "<b style='font-size: 40px;'>".$arr[$i]."</>"; } } else{ /*----Print Final Output----*/ for ($i=0; $i < 8 ; $i++) { echo "<b style='font-size: 40px;'>".$arr[$i]."</>"; } }
?>
Output:


How to run?
1. Install wampserver / Xamppserver.
2. copy the program and paste in a notepad file.
3. Save the program with .php extension into
C:\xampp\htdocs (or another drive where xampp is installed)
C:\wamp64\www(or another drive where wampserver is installed)
4. Run the server & Open browser and type:
localhost/yourfilename.php







Comments