如何使用PHP代码找到每天的特定时间间隔
在我的学生出勤项目中,在每天上午9点45分至10点30分之间,老师应该标记学生的出勤情况 所以,老师应该只能在那个时间给他们的出勤率打分。其余时间的学生名单应禁用 在这里,我面临一个问题,发现服务器当前时间在每天上午9:45到10:30之间如何使用PHP代码找到每天的特定时间间隔,php,mysql,Php,Mysql,在我的学生出勤项目中,在每天上午9点45分至10点30分之间,老师应该标记学生的出勤情况 所以,老师应该只能在那个时间给他们的出勤率打分。其余时间的学生名单应禁用 在这里,我面临一个问题,发现服务器当前时间在每天上午9:45到10:30之间 $now = time(); $today = strtotime('9:50'); //do not know how to find current date with time interval 9.45am and 10.30am if (($t
$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";
}
请帮我找到解决办法
$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";
}
我希望这是不言自明的,但如果你有任何问题,请提问。我不同意,使用碳元素是比DateTime类更好的处理日期和时间的方法;但是,请随意使用carbon@AdityaThakursir发布答案,它不起作用,当我回显$date1、$date2、$date3时,没有显示任何内容。你不回显它们,没有必要
$status
是您正在使用的值。它使用服务器时间,如果服务器时间不是您想要的时间,您可以更改时区
$current_time = "10:31 am";