2012-05-27 60 views
0

如何在php中檢查時間是否可以說12,如果是,執行一些代碼。 這是我迄今爲止。php日期時間運算符

我希望代碼在特定時間進行,並且只在當時每天進行。

if (date('H') == 20) 
{ 
//code to be carried out 

CODE 
CODE 
CODE 
echo ("lol"); 
} 

然而,無論時間如何,cocde似乎都在運行!

即使時間不是晚上8點,程序也會每次回覆lol。

任何幫助表示讚賞感謝

+0

'echo date('H')'看看它給你什麼時間。 – Norse

+1

@Norse H =一小時24小時格式,前導零00到23 –

+0

@LawrenceCherone啊,不知道。編輯我的迴應。 – Norse

回答

0

它不是呼應了在我的測試:

http://codepad.org/7ZvAKHWh

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 
+0

讓我檢查一下 – foshoeiyyy

+0

好像在做我的 – foshoeiyyy

+0

不是在codpad上做的,雖然 – foshoeiyyy

-1

您的代碼,除非這是不是---嘗試和複製應該工作原始來源

2

如果你想每天在特定時間執行一個php腳本,那麼看看cron jobs

有一個關於如何在cPanel中設置cron作業的教程,here