两个php日期控制类实例

由于工作需要我找了二个时间日期控制,这个不用js只要php实现的,因为要带参考查询操作,感兴趣的朋友可以参考一下,我自己用的是第二个,所以第二个己作了修改.

实例一,代码如下:

复制代码 代码如下:

<?php
class Calendar
{
 var $month;
 var $year;
 
    function __construct($year,$month)
    {
     $this->year=$year;
  $this->month=$month;
 }
 
 function endday()
 {
  $daydate=date("d",mktime(0,0,0,$this->month,35,$this->year));
  $endday=35-$daydate;
  return $endday;
 }
 
 function oneday_week()
 {
  $oneday_week=date("w",mktime(0,0,0,$this->month,1,$this->year));
  return $oneday_week;
 }
 
 function title_link()
 {
  if(!isset($this->month) && !isset($this->year))
  {
   $this->year  = date("Y");
   $this->month = date("m");
        }
  
  $lastmonth=$this->month-1;
  $nextmonth=$this->month+1;
  $lastyear=$this->year;
  $nextyear=$this->year;
 
        if($this->month <= 1)
        {
         $lastmonth=12;
   $nextmonth=$this->month+1;
   $lastyear=$this->year-1;
   $nextyear=$this->year;
  }
        elseif ($this->month >= 12) 
        {
         $lastmonth=$this->month-1;
         $nextmonth=1;
   $lastyear=$this->year;
   $nextyear=$this->year+1;
        }
 
        $str ="<td colspan='2'><div><a href=$PHP_SELF?year=".$lastyear."&month=".$lastmonth."&><<<</a></div></td>";
  $str.="<td colspan='3'><div>".$this->year."--".$this->month."</div></td>";
  $str.="<td colspan='2'><div><a href=$PHP_SELF?year=".$nextyear."&month=".$nextmonth."&>>>></a></div></td>";
  return $str;
 }
 
 function Show_Calendar()
 {
        echo "<table border=5><tr>".$this->title_link()."</tr><tr>";
        $weekarray=array("日","一","二","三","四","五","六");
        
        for($k=0;$k<=6;$k++)
        {
         echo "<td><div>".$weekarray[$k]."</div></td>";
        }
        echo "</tr>";
        
        for($i=0;$i<=5;$i++)
        {
         echo "<tr>";
         for($j=1;$j<=7;$j++)
         {
     $math=( $j - $this->oneday_week() ) + 7 * $i;
    
          echo "<td><div>";
    
          if($math <= $this->endday() and $math>=1)
     {
   echo $math;
     }
    
         echo "</div></td>";
         }    
         echo "</tr>";     
        }
  echo "</table>";
 }
}
$calendar=new Calendar($_GET['year'],$_GET['month']);
$calendar->month=$_GET['month'];
$calendar->year=$_GET['year'];
$calendar->Show_Calendar();
?>


实例二,代码如下:

复制代码 代码如下:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/bf80c67174d68e781011a7c0de69e187.html