請嘗試以下代碼,我會在數據庫存儲爲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;
}
?>
檢查當前時間和寫conditions..ie,如果當前時間<11點或當前時間<4時再做以下幾點 – 2013-02-27 12:16:08
@用戶:我如何檢查它是<上午11點還是<下午4點?我如何顯示明天上午11點和下午4點以及接下來的幾天?我如何在MySQL中存儲選定的時間? – ProgrammerGirl 2013-02-27 12:25:27
是週末考慮?假期? – SparKot 2013-02-27 12:26:03