请尝试以下代码,我会将 DATETIME 存储在数据库中:您可以根据需要进行优化,它应该为您提供基本的逻辑概念:
<?php
$end_date = mktime(0, 0, 0, date("m") , date("d")+4, date("Y"));
$cnt = 0;
$day = 0;
$current_hour = date("H");
// To test with various values, uncomment below line and assign any hour
// $current_hour = "12";
if($current_hour < 11)
{
$day = 0;
$ts = mktime(11, 0, 0, date("m") , date("d"), date("Y"));
echo "<br>".date("Y-m-d H:i:s",$ts);
$ts = mktime(16, 0, 0, date("m") , date("d"), date("Y"));
echo "<br>".date("Y-m-d H:i:s",$ts);
$cnt = 2;
$day = $day + 1;
}
elseif($current_hour < 16)
{
$day = 0;
$ts = mktime(16, 0, 0, date("m") , date("d")+$day, date("Y"));
echo "<br>".date("Y-m-d H:i:s",$ts);
$cnt = 1;
$day = $day + 1;
}
elseif($current_hour >= 16)
{
$day = $day + 1;
}
while($cnt <= 8)
{
$ts = mktime(11, 0, 0, date("m") , date("d")+$day, date("Y"));
echo "<br>".date("Y-m-d H:i:s",$ts);
$cnt = $cnt + 1;
if($cnt >=8) break;
$ts = mktime(16, 0, 0, date("m") , date("d")+$day, date("Y"));
echo "<br>".date("Y-m-d H:i:s",$ts);
$cnt = $cnt + 1;
$day = $day + 1;
if($cnt >=8) break;
}
?>