在我的学生出勤项目中,每天从上午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.30amif (($today - $now) > 0) { $status = "disabled";} else { $status = "active";}请帮助我找到解决方案。
1 回答
慕田峪4524236
TA贡献1875条经验 获得超5个赞
$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)
{
$status = "active";
} else {
$status = "disabled";
}
要测试而无需等待正确的时间,可以这样设置$current_time:
$current_time = "10:31 am";
我希望它是不言自明的,但是如果您有任何疑问,请提出。和/或查看dateTime类
- 1 回答
- 0 关注
- 134 浏览
添加回答
举报
0/150
提交
取消