如何将PHP中的时间从AM / PM转换为24小时格式?
例如,我有一个时间以这种格式:
eg.
09:15 AM
04:25 PM
11:25 AM
如何将其转换为:
09:15
16:25
23:25
目前我的代码是:
$format_time = str_replace(" AM", "", $time, $count);
if ($count === 0){
$format_time = strstr($time, ' PM', true);
$format_time = ......
}
但是,似乎有一些更简单,更优雅的方法来做到这一点?
$time = '23:45';
echo date('g:i a', strtotime($time));
我如何将上述样品适合我的情况?谢谢。