php判断当前时间是否在某个时间段内的代码
<?php//设定时间格式$timeFormat='H:i';//24小时格式//指定的开始时间点$startTime='08:00';//指定的结束时间点$endTime='17:00';//当前时间$now=newDate
<?php require 'conn.php'; header("Content-type: text/html; charset=utf-8"); // 设定时间格式 $timeFormat = 'H:i'; // 24小时格式 // 指定的开始时间点 $startTime = '01:00'; // 指定的结束时间点 $endTime = '02:00'; // 当前时间 $now = new DateTime('now', new DateTimeZone('Asia/Shanghai')); // 设置时区 // 创建开始时间对象 $start = DateTime::createFromFormat($timeFormat, $startTime); // 创建结束时间对象 $end = DateTime::createFromFormat($timeFormat, $endTime); // 将时间对象转换为时间戳 $nowTimestamp = $now->getTimestamp(); $startTimestamp = $start->getTimestamp(); $endTimestamp = $end->getTimestamp(); // 检查当前时间是否在指定时间点之间 if ($nowTimestamp >= $startTimestamp && $nowTimestamp <= $endTimestamp) { //while(1==1){ $sql = "select * from xiaochu where datediff(addtime,now())=-1 limit 1"; $result = mysqli_query($con,$sql); if($row = mysqli_fetch_array($result)){ $id = $row['id']; $img = $row['img']; $img_yanma = $row['img_yanma']; unlink($img); // 删除原图 unlink($img_yanma); // 删除原图 $sql1 = "delete from xiaochu where id=".$id; mysqli_query($con,$sql1); } //} } else { echo "当前时间不在指定时间点之间"; } ?>