This article describes the method of converting 12-hour clock to 24-hour clock in php. Share it with everyone for your reference. The details are as follows:
php converts 12-hour clock to 24-hour clock. The input format is: 02:30:00 pm converted to: 14:30:00
<?php function to_24_hour($hours,$minutes,$seconds,$meridiem){ $hours = sprintf('%02d',(int) $hours); $minutes = sprintf('%02d',(int) $minutes); $seconds = sprintf('%02d',(int) $seconds); $meridiem = (strtolower($meridiem)=='am') ? 'am' : 'pm'; return date('H:i:s', strtotime("{$hours}:{$minutes}:{$seconds}{$meridiem}")); } echo to_24_hour( 1, 2, 3, 'pm' ); // Returns 13:02:03 echo to_24_hour( '02', '30', '00', 'pm' ); // Returns 14:30:00 ?>
I hope this article will be helpful to everyone’s PHP programming design.