如何只显示时间并更改为 24 小时制


How to display just the time and change to 24hr clock

我正在使用以下脚本当前显示日期和时间。

不想显示日期,但似乎无法在不工作的情况下将其取出,而且我如何将时钟更改为 24 小时,因为它目前是 12 小时。

<?php
$hourdiff = 0; // Replace the 0 with your timezone difference (;
$site = date("l, d F Y g:i a",time() + ($hourdiff * 3600));
echo $site;
?>

希望有人能帮忙。

谢谢。

a   Lowercase Ante meridiem and Post meridiem        am or pm
A   Uppercase Ante meridiem and Post meridiem        AM or PM
B   Swatch Internet time                             000 through 999
g   12-hour format of an hour without leading zeros  1 through 12
G   24-hour format of an hour without leading zeros  0 through 23
h   12-hour format of an hour with leading zeros     01 through 12
H   24-hour format of an hour with leading zeros     00 through 23
i   Minutes with leading zeros                       00 to 59
s   Seconds, with leading zeros                      00 through 59

根据您的代码,这将是

<?php
$hourdiff = 0; // Replace the 0 with your timezone difference (;
$site = date("l, d F Y H:i",time() + ($hourdiff * 3600));
echo $site;
?>

请参考,PHP日期函数

查看 php 时间和日期

尝试"H"24小时

使用 H 或 G 而不是 g 来获取 24 小时格式

不确定你用($hourdiff * 3600)逻辑做什么,任何数字乘以 0 都是 0。您应该阅读与日期函数相关的文档。

试试这个:

$site = date('H:i a');
echo $site;

只需要更改日期参数。 查看日期手册。

$site = date('H : i: s');

RTM,将来也向我们展示您如何尝试删除日期...

g   12-hour format of an hour without leading zeros 1 through 12
G   24-hour format of an hour without leading zeros 0 through 23
h   12-hour format of an hour with leading zeros    01 through 12
H   24-hour format of an hour with leading zeros    00 through 23
i   Minutes with leading zeros  00 to 59
s   Seconds, with leading zeros 00 through 59

$site = date("G:i a",time() + ($hourdiff * 3600));