【问题标题】:Availability Calendar Errors on Mon 31 Mar 20142014 年 3 月 31 日星期一的可用性日历错误
【发布时间】:2014-01-21 16:06:36
【问题描述】:

我正在创建一个页面来显示假期出租的可用性。经过大量学习(新手),我创建了以下代码来显示可用性。它的目标是在页面的一行中显示一个日历表并填写预订日期(注意:最终版本从 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>";

?>

【问题讨论】:

  • 怎么不工作了?
  • 如果日期是 3 月 31 日或之后,它不会将单元格填充为红色。
  • 查看时间戳显示的内容后,我想知道这是否与 3 月 30 日更改的夏令时有关?
  • 我设法通过在 3 月 30 日增加一个小时来实现这一点。夏令时有什么不同的弥补方式吗?

标签: mysql calendar datepicker


【解决方案1】:

问题是在去年 3 月的星期日更改时间。 2014 年 3 月 31 日是更改时间后的第一个星期一。这个问题每年都会重复,在更改时间后的第一个星期一。 如果这是服务器问题或代码问题,我现在不知道。 而且我现在不知道,例如,如果在 4 月,问题将出现在 10 月更改时间后的第一个星期一。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-20
    • 1970-01-01
    • 2015-06-04
    相关资源
    最近更新 更多