How do you convert between 12 hour time and 24 hour time in PHP?
I have a time as a string, for example:
$time = '5:36 pm';
I require this to be in 24 hour format (i.e. 17:36
), however I don't know which functions I need to use to convert it. Please help.
Solution 1:
// 24-hour time to 12-hour time
$time_in_12_hour_format = date("g:i a", strtotime("13:30"));
// 12-hour time to 24-hour time
$time_in_24_hour_format = date("H:i", strtotime("1:30 PM"));