检查当前的EST时间是否在午夜(00:00:00)和00.00.10之间
我想在午夜运行一个cron作业,但我想确保cron作业在00.00.10之后永远不会调用脚本,我的意思是在cron作业中必须有最多10秒钟(由于任何原因)< / p>
所以我的问题是如何检查当前的估计时间是否在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")
}
答案 0 :(得分: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
}
供参考,见: