如何在PHP中将时间从AM / PM转换为24小时格式? [英] How to convert the time from AM/PM to 24 hour format in PHP?
本文介绍了如何在PHP中将时间从AM / PM转换为24小时格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如,我有一个时间在这种格式
例如。
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));
如何适应上述样本在我的情况?谢谢
解决方案
尝试这个
echo date(G:i,strtotime($ time));
或者你也可以这样尝试
<$ echo $ {code> echo date(H:i,strtotime(04:25 PM));
For example , I have a time in this format
eg.
09:15 AM
04:25 PM
11:25 AM
How to convert it to
09:15
16:25
23:25
Currently my code is :
$format_time = str_replace(" AM", "", $time, $count);
if ($count === 0){
$format_time = strstr($time, ' PM', true);
$format_time = ......
}
However, it seems there are some easier and elegant way to do this?
$time = '23:45';
echo date('g:i a', strtotime($time));
How to fit the above sample in my case? Thanks
解决方案
Try with this
echo date("G:i", strtotime($time));
or you can try like this also
echo date("H:i", strtotime("04:25 PM"));
这篇关于如何在PHP中将时间从AM / PM转换为24小时格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文