2017-07-16 93 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

相关问题