最模板 - 外贸网站建设,外贸网站模板

最模板

当前位置: 首页 > 建站教程 > php教程 >

两个php日期控制类

时间:2014-09-06 14:30来源:未知 作者:最模板zuimoban 点击:
由于工作需要我找了二个时间日期控制,这个不用js只要php实现的,因为要带参考查询所以操作了操作,有需要的朋友可以参考一下,我自己用的是第二个,所以第二个己作了修改. 实例一,代码

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

实例一,代码如下:

  1. <?php 
  2.  
  3. class Calendar 
  4.  var $month
  5.  var $year
  6.  
  7.     function __construct($year,$month
  8.     { 
  9.      $this->year=$year
  10.   $this->month=$month
  11.  } 
  12.  
  13.  function endday() 
  14.  { 
  15.   $daydate=date("d",mktime(0,0,0,$this->month,35,$this->year)); 
  16.   $endday=35-$daydate
  17.   return $endday
  18.  } 
  19.  
  20.  function oneday_week() 
  21.  { 
  22.   $oneday_week=date("w",mktime(0,0,0,$this->month,1,$this->year)); 
  23.   return $oneday_week
  24.  } 
  25.  
  26.  function title_link() 
  27.  { 
  28.   if(!isset($this->month) && !isset($this->year)) 
  29.   { 
  30.    $this->year  = date("Y"); 
  31.    $this->month = date("m"); 
  32.         } 
  33.          
  34.    
  35.   $lastmonth=$this->month-1; 
  36.   $nextmonth=$this->month+1; 
  37.   $lastyear=$this->year; 
  38.   $nextyear=$this->year; 
  39.  
  40.         if($this->month <= 1) 
  41.         { 
  42.          $lastmonth=12; 
  43.    $nextmonth=$this->month+1; 
  44.    $lastyear=$this->year-1; 
  45.    $nextyear=$this->year; 
  46.   } 
  47.         elseif ($this->month >= 12)  
  48.         { 
  49.          $lastmonth=$this->month-1; 
  50.          $nextmonth=1; 
  51.    $lastyear=$this->year; 
  52.    $nextyear=$this->year+1; 
  53.         } 
  54.  
  55.         $str ="<td colspan='2'><div align='center'><a href=$PHP_SELF?year=".$lastyear."&month=".$lastmonth."&><<<</a></div></td>"
  56.   $str.="<td colspan='3'><div align='center'>".$this->year."--".$this->month."</div></td>"
  57.   $str.="<td colspan='2'><div align='center'><a href=$PHP_SELF?year=".$nextyear."&month=".$nextmonth."&>>>></a></div></td>"
  58.   return $str
  59.  } 
  60.  
  61.  
  62.  function Show_Calendar() 
  63.  { 
  64.         echo "<table width='181' border=5><tr class='tr.title'>".$this->title_link()."</tr><tr>"
  65.         $weekarray=array("日","一","二","三","四","五","六"); 
  66.          
  67.         for($k=0;$k<=6;$k++) 
  68.         { 
  69.          echo "<td><div align='center'>".$weekarray[$k]."</div></td>"
  70.         } 
  71.         echo "</tr>"
  72.          
  73.         for($i=0;$i<=5;$i++) 
  74.         { 
  75.          echo "<tr>"
  76.          for($j=1;$j<=7;$j++) 
  77.          { 
  78.     $math=( $j - $this->oneday_week() ) + 7 * $i
  79.      
  80.           echo "<td><div align='center'>"
  81.      
  82.           if($math <= $this->endday() and $math>=1) 
  83.     { 
  84.          echo $math
  85.     } 
  86.      
  87.          echo "</div></td>"
  88.          }     
  89.          echo "</tr>";      
  90.         } 
  91.   echo "</table>"
  92.            
  93.  } 
  94.  
  95. /*$calendar=new Calendar($_GET['year'],$_GET['month']); 
  96. //$calendar->month=$_GET['month']; 
  97. //开源代码vcphp.com 
  98. //$calendar->year=$_GET['year']; 
  99. $calendar->Show_Calendar();*/ 
  100.  
  101. ?> 

实例二,代码如下:

  1. <?php 
  2. header("content-type:text/html;charset=utf-8"); 
  3. ?> 
  4. <meta http-equiv="content-type" content="text/html;charset=utf-8"
  5.  
  6. <link href="statics/css/zhaoshang.css" rel="stylesheet" type="text/css"
  7. <div class="rili"
  8. <?php 
  9. if(!emptyempty($_GET)){ 
  10.     $year = isset($_GET['year'])?$_GET['year']:date('y'); 
  11.     $month = isset($_GET['month'])?$_GET['month']:date('m'); 
  12.  $day = isset($_GET['day'])?$_GET['day']:date('d'); 
  13. if(emptyempty($year)){ 
  14.     $year = date('Y'); 
  15. if(emptyempty($month)){ 
  16.     $month = date('m'); 
  17.  
  18. if(emptyempty($month)){ 
  19.     $days = date('d'); 
  20.  
  21. $start_weekday = date('w',mktime(0,0,0,$month,1,$year)); 
  22. //echo $start_weekday; 
  23. $days = date('t',mktime(0,0,0,$month,1,$year)); 
  24. //echo $days; 
  25. $week = array('日','一','二','三','四','五','六'); 
  26. $i = 0; 
  27. $k = 1; 
  28. $j = 0; 
  29. echo '<table >'
  30. echo '<tr><td colspan = 7 style ="text-align:center; width:250px; background:#d5e5f6; border-bottom:1px solid #333366;">'.$year.'年'.$month.'月'.'</td></tr>'
  31. echo '<tr>'
  32. for($i = 0;$i < 7;$i++){ 
  33.     echo '<td>'.$week[$i].'</td>'
  34. echo '</tr>'
  35. echo '<tr>'
  36. for($j = 0;$j < $start_weekday;$j++){ 
  37.     echo '<td style="color:#f1f8fc;">'.$j.'</td>'
  38. while($k <= $days){ 
  39.     if($k == $day){ 
  40.         echo '<td style="color:red"><a href="?year='.$year.'&month='.$month.'&day='.$k.'"><span style="color:red">'.$k.'</span></a></td>'
  41.     }else
  42.         echo '<td><a href="?year='.$year.'&month='.$month.'&day='.$k.'">'.$k.'</a></td>'
  43.     } 
  44.     if(($j+1) % 7 == 0){ 
  45.         echo '</tr><tr>'
  46.     } 
  47.     $j++; 
  48.     $k++; 
  49. while($j % 7 != 0){ 
  50.     echo '<td style="color:#f1f8fc;">'.$j.'</td>'
  51.     $j++; 
  52. echo '</tr>'
  53.  
  54. echo '<tr style="background:#d5e5f6;">'
  55. echo "<td><a href=?".lastYear($year,$month).">".'<<'.'</a></td>'
  56. echo "<td><a href=?".lastMonth($year,$month).">".'<'.'</a></td>'
  57. echo '<td colspan = 3 style="width:105px;" >'
  58. echo '<form name = "myform" method = "GET">'
  59. echo '<select name = year  class="year">'
  60. for($start_year = 1970;$start_year<2039;$start_year++){ 
  61.  $selected=''
  62.  if$year== $start_year ) { $selected='selected'; } 
  63.  echo '<option value ='$start_year.' '.$selected.'>'.$start_year.'</option>'." nt"
  64. echo '</select>'
  65. echo '<select name = month class="month">'
  66. for($start_month = 1;$start_month<=12;$start_month++){ 
  67.  $selected=''
  68.  if$month== $start_month ) { $selected='selected';} 
  69.  echo '<option value = '.$start_month.' '.$selected.'>'.$start_month.'</option>'." nt"
  70. echo '</select>'
  71. /*echo '月';*/ 
  72. /*echo '<input type = "submit" name = "search" value = "查询">';*/ 
  73. echo '</form>'
  74. echo '</td>'
  75. echo "<td><a href=?".nextYear($year,$month).">".'>>'.'</a></td>'
  76. echo "<td><a href=?".nextMonth($year,$month).">".'>'.'</a></td>'
  77. echo '</tr>'
  78. echo '</table>'
  79.  
  80. function lastYear($year,$month){ 
  81.  $year = $year-1; 
  82.  return "year=$year&month=$month"
  83. function lastMonth($year,$month){ 
  84.  if($month == 1){ 
  85.   $year = $year -1; 
  86.   $month = 12; 
  87.  }else
  88.   $month--; 
  89.  } 
  90.  return "year=$year&month=$month"
  91. function nextYear($year,$month){ 
  92.  $year = $year+1; 
  93.  return "year=$year&month=$month"
  94. function nextMonth($year,$month){ 
  95.  if($month == 12){ 
  96.   $year = $year +1; 
  97.   $month = 1; 
  98.  }else { 
  99.   $month++; 
  100.  } 
  101.  return "year=$year&month=$month"
  102.  
  103. ?> 
  104. </div>
  105.  
(责任编辑:最模板)
------分隔线----------------------------
栏目列表
推荐内容
  • 用PHP控制您的浏览器cache

    Output Control 函数可以让你自由控制脚本中数据的输出,它非常地有用,特别是对于:当你想在数据...

  • php数字格式化

    之前曾经一直使用自己定义的数字格式化方法,原来PHP一直有个数字格式化函数的,呵呵~例如...

  • php session会话使用方法详解

    本文章来给各位php 初学者介绍一篇关于php中全局变量session会话的基本使用方法 Session是什么...

  • PHP生成动态WAP页面

    WAP(无线通讯协议)是在数字移动电话、个人手持设备(PDA等)及计算机之间进行通讯的开放...

  • php使用ajax示例

    AJAX介绍 :Ajax是使用客户端脚本与Web服务器交换数据的Web应用开发方法。Web页面不用打断交互流...

  • PHP开发中接收复选框信息的方法

    PHP接收多个同名复选框信息不像ASP那样自动转换成为数组,这给使用带来了一定不便,但是还是有...