Category Covered

convert 12 hour time to 24 hour time

If you want to convert 12 hour time or meridian time to 24 hour time in php then follow the instruction

For example i have an array like that

 

[time_to] => Array
   (
    [hour] => 02
    [min] => 00
    [meridian] => pm
)

Use the following code to convert it into 24 hours time. Here i have created a $date object

 

$date = new DateTime($time_to['hour'] . ':' . $time_to['min'] . ' ' . $time_to['meridian']);
echo $date->format('H:i:s');

 

The result will be 14:00:00

 

PHP convert 24 hour time to 12 hour