2012-04-14 48 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

相關問題