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
4 11 |
<🎜>function to_24_hour($hours,$minutes,$seconds,$meridiem){<🎜>
<🎜>$hours = sprintf(' d',(int) $hours);<🎜>
<🎜>$minutes = sprintf(' d',(int) $minutes);<🎜>
<🎜>$seconds = sprintf(' d',(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<🎜>
<🎜>?>
|