如何每天使用PHP代码找到特定的时间间隔

在我的学生出勤项目中,每天从上午9.45到上午10.30之间,老师应标记出学生的出勤情况。


因此,老师应该只能在该时间标记出勤。其余时间应禁用学生列表。


在这里,我面临一个问题,发现服务器当前时间每天都在9.45am到10.30am之间达到。


$now = time();  

$today = strtotime('9:50');

//do not know how to find current date with time interval 9.45am and 10.30am

if (($today - $now) > 0) {

    $status = "disabled";

} else {

    $status = "active";

}

请帮助我找到解决方案。


人到中年有点甜
浏览 135回答 1
1回答

慕田峪4524236

$current_time = date('h:i:s a'); //now$start = "9:50 am";$finish = "10:30 am";$date1 = DateTime::createFromFormat('H:i a', $current_time);$date2 = DateTime::createFromFormat('H:i a', $start);$date3 = DateTime::createFromFormat('H:i a', $finish);if ($date1 > $date2 && $date1 < $date3){&nbsp; &nbsp; $status = "active";} else {&nbsp; &nbsp; $status = "disabled";}要测试而无需等待正确的时间,可以这样设置$current_time:$current_time = "10:31 am";我希望它是不言自明的,但是如果您有任何疑问,请提出。和/或查看dateTime类
打开App,查看更多内容
随时随地看视频慕课网APP