如何判断22点-24点之间加5分钟,凌晨1点到2点加5分钟,其余时间是加10分钟?要显示2019-11-21 22:00:00

$drawTime=date('Y-m-d H:i:s',$row["time"]+600); 这段代码如何判断22点-24点之间加5分钟,凌晨1点到2点加5分钟,其余时间是加10分钟? 不要转换时间的,要显示2019-11-21 22:00:00

$servername = "localhost";
$username = "qxc";
$password = "123456";
$dbname = "qxc";

// 创建连接
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("连接失败: " . $conn->connect_error);
}

$sql = "SELECT * FROM qxc.jz_data where type='6' order by number desc LIMIT 1";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
// 输出数据
while($row = $result->fetch_assoc()) {
$number=$row["number"];
$data=$row["data"];
$arr=$row["data"];
$num1=$arr[0]+$arr[2]+$arr[4]+$arr[6]+$arr[8];

$time=date('Y-m-d H:i:s',$row["time"]);
$drawTime=date('Y-m-d H:i:s',$row["time"]+300);
$serverTime=date('Y-m-d H:i:s');
$drawCount=intval(substr($number,-3));
}
} else {

}

$conn->close();

2个回答

if (date("H", row["time"]) > 22 || date("H", row["time"]) < 2)
$drawTime=date('Y-m-d H:i:s',$row["time"]+300);
else
$drawTime=date('Y-m-d H:i:s',$row["time"]+600);

$time = date('H',$row["time"]);
        $h = ['22-24','1-2'];//控制时间段
        $flag = false;
        foreach ($h as $val){
            list($start_time,$end_time) = explode('-',$val);
            if($start_time <= $time && $time < $end_time){
                $flag = true;
                break;
            }
        }
        if($flag){//加5分钟
            echo $row["time"] + 300;
        }else{//加10分钟
            echo $row["time"] + 600;
        }

写了个demo,应该可以满足你的需求

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问