/ Published in: PHP
Convert 12-hour time format with hour, minutes, seconds, and meridiem into 24-hour format. Performs data correction to make sure hours, minutes and seconds have leading zeros if needed.
The trick here is to use strtotime() where we pass the time string in this format: "hh:mm:ss meridiem"
Example: "02:30:00 pm"
The trick here is to use strtotime() where we pass the time string in this format: "hh:mm:ss meridiem"
Example: "02:30:00 pm"
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php function to_24_hour($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 ?>