在PHP中如何在12小时和24小时之间转换? [英] How do you convert between 12 hour time and 24 hour time in PHP?
本文介绍了在PHP中如何在12小时和24小时之间转换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个时间作为字符串,例如:
I have a time as a string, for example:
$time = '5:36 pm';
我要求此格式为24小时格式(即17:36
),但是我不知道我需要使用哪些函数对其进行转换.请帮忙.
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.
推荐答案
// 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"));
这篇关于在PHP中如何在12小时和24小时之间转换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文