且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP如何将12小时制时间转换为24小时时间?

更新时间:2023-02-26 16:11:58

文档 date() H 格式字符以24小时格式给出小时。另外,如果您不想在中午之前的几个小时内领先 0 ,则可以使用 G

From the docs for date(): The H format character gives the hour in 24h format. Also, you can use G if you do not want the leading 0 for hours before noon.

示例(如果当前时间是7-something-AM)

date('H:i:s ') - >07:22:13

date('G:i:s') - > 7:22:13

Examples (if current time was seven-something-AM)
date('H:i:s') -> "07:22:13"
date('G:i:s') -> "7:22:13"

对于您的具体情况:

$timestamp = date("d/m/Y H:i:s", time());