2012-04-14 136 views
-2

我正在使用以下脚本来显示日期和时间。如何仅显示时间并更改为24小时制

我不想显示日期,但似乎无法拿出它没有它不工作,也如何将时钟更改为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; 
?> 

希望有人可以提供帮助。

谢谢。

+3

难道你看[PHP文档(http://uk3.php.net/manual /en/function.date.php)? – richsage 2012-04-14 21:21:34

回答

0

php time & date

尝试“H”为24小时

+0

谢谢大家,它已经排序。 – jameswildi 2012-04-14 21:29:35

+0

@jameswildi:如果您发现答案可以接受,请接受。谢谢。 – 2012-04-16 02:10:51

0

采用H或G,而不是G进入24小时格式

0

不知道你是用($hourdiff * 3600)逻辑做什么,任何数字乘以由0表示。您应该阅读与date函数相关的文档。

试试这个:

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

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

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

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 

$网站=日期( “G:IA”,时间()+($ hourdiff * 3600));

1
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 date function

相关问题