我正在创建一个页面,以显示假期租赁的可用性。经过大量学习(新手),我创建了以下代码以显示可用性。它的目的是在页面上的一行中显示一个日历表并填写预订日期(注意:最终版本从MySQL表中获得日期)。除非开始日期是2014年3月31日或以后,否则工作正常。我敢肯定,我错过了一些明显的东西,但无法确定错误在哪里。任何帮助都非常感谢。
<?php
$calendarstart = mktime(0,0,0,12,01,13);//Calendar Start as a Unix Timestamp
$calendarend = mktime(0,0,0,5,18,14); //Calendar End as a Unix Timestamp
echo "<table border='1' width='800' cellspacing='0' cellpadding='5' align='center'>
<tr>
<th colspan='31' align='center' >December 2013</th>
<th colspan='31' align='center'>January 2014</th>
<th colspan='28' align='center'>February 2014</th>
<th colspan='31' align='center'>March 2014</th>
<th colspan='30' align='center'>April 2014</th>
<th colspan='18' align='center'>May 2014</th>
</tr>";
echo "<tr>";
for ($count=$calendarstart; $count<=($calendarend); ($count=$count+86400)) // loop to add 1 day to Calendar
{
$startdate= (date(strtotime("Sun 30 Mar 2014"))); //Start Date from MYSQL Table Record as a Unix Timestamp
$enddate= (date(strtotime("Thu 10 Apr 2014"))); //End Date from MYSQL Table Record as a Unix Timestamp
if ($startdate==$count) // Is Recordset start date the same as the Calendar
{
echo "<td align='center' bgcolor='#FF0000'>".date("D d ",$count)."<br>"; // make cell background red and write date in
$duration=$startdate+86400; // set variable to count duration
$durationend=$enddate;
}
elseif ($duration==$count)
{
if ($duration<$durationend)
{
echo "<td align='center' bgcolor='#FF0000' >".date("D d ",$count)."<br>"; // make cell background red and write date in
if ($count<($durationend-86400))
{
$duration=$duration+86400; // add 1 day
}
}
}
else
{
echo "<td align='center' bgcolor='#FFFFFF'>".date("D d ",$count)."<br>"; //make cell background white and write date in
}
}
echo "</tr>";
echo "</table>";
?>
问题是在去年三月周日更改小时。2014年3月31日是换小时后的第一个星期一。该问题每年都会在更改小时后的第一个星期一重复。现在,如果这是服务器问题或代码问题,我现在不会。例如,我现在不会在4月,问题将是在10月更改小时后的第一个星期一。