2017-07-16 94 views
0

如果當前EST時間是午夜(00:00:00)和00.00.10如何檢查是否當前EST時間是00.00.00之間 - 檢查00.00.10

之間我想運行一個cron作業在午夜時分,但我想確保cron job在00.00.10之後永遠不會調用腳本,我的意思是在cron job中必須有最多10秒的dealy(由於任何原因)

所以我的問題是如何檢查如果當前時間在00.00.00-00.00.10之間

if($current_est_time is 00.00.00 - 00.00.10){ 
    // Run the code 
    } 
else{ 
    die("Sorry cron job was not called at correct time") 
} 

回答

1

試試這個:

$now = new \DateTime(
    'now', 
    new \DateTimeZone('America/New_York') 
); 

$formatted = $now->format('H:i:s'); 

if ('00:00:00' <= $formatted && '00:00:10' >= $formatted) { 
    // good time 
} 

僅供參考,請參閱:

+0

是的!很棒!謝謝 ! – beginner

+0

@beginner好極了!那麼你能接受這個答案嗎? – localheinz

+0

OH,對不起,我忘了:) – beginner

相關問題