PHP如何将12小时制时间转换为24小时时间? [英] How do I convert 12 hour clock time into 24 hour clock time in PHP?

查看:561
本文介绍了PHP如何将12小时制时间转换为24小时时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下功能,而我希望以24小时的格式进行时间,但这样可以让我在12小时内获得时间:

I am using following function and I want time in 24hr clock format but this gives me time in 12hrs:

<?php
date_default_timezone_set('Asia/Kolkata');
$timestamp =  date("d/m/Y h:i:s", time());
print $timestamp ;
?>

我做错了什么?

推荐答案

文档 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());

这篇关于PHP如何将12小时制时间转换为24小时时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆