VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > PHP >
  • 非常简单的日历类

  1. date_default_timezone_set("etc/gmt-8"); 
  2. class calendar{ 
  3. var $t = array(); 
  4. var $datesofmonth = array('1'=>'31','2'=>'28','3'=>'31','4'=>'30','5'=>'31','6'=>'30','7'=>'31','8'=>'31','9'=>'30','10'=>'31','11'=>'30','12'=>'31'); 
  5. var $y,$m,$d; 
  6. function set($time){ 
  7. $this->t = getdate($time); 
  8. $this->y = $this->t['year']; 
  9. $this->m = $this->t['mon']; 
  10. $this->d = date('d',$time); 
  11. } 
  12. function isrun(){ 
  13. return ($this->y%400==0 || ($this->y%4==0 && $this->y%100==0)) ? 1 : 0; 
  14. } 
  15. function first(){ 
  16. $time = mktime(0,0,0,$this->m,1,$this->y); 
  17. $time = getdate($time); 
  18. return $time['wday']; 
  19. } 
  20. function html(){ 
  21. $isrun = $this->isrun(); 
  22. $this->datesofmonth[2] = $isrun==1 ? 29: 28; 
  23. $html .= "<table style='border:solid 1px black;'>n"; 
  24. $html .= "<tr><th><a href=''>上一月</a></th><th colspan='5'>{$this->y}年 {$this->m}月</th><th><a href=''>下一月</a></th><tr>n"; 
  25. $html .= "<tr><td>星期天</td><td>星期一</td><td>星期二</td>111cn.net<td>星期三</td><td>星期四</td><td>星期五</td><td>星期六</td></tr>n"; 
  26. $html .= "<tr>n"; 
  27. $first = $this->first(); 
  28. for($i=0; $i<$first; $i++){ 
  29. $html .= "<td></td>"; 
  30. } 
  31. $count = $this->datesofmonth[$this->m]+$first; 
  32. for ($i=1; $i<= $this->datesofmonth[$this->m]; $i++){ 
  33. $style = $i==$this->d ? ' style="color:red;font-weight:bold;"' : '' ; 
  34. $html .= "<td align='center'{$style}>$i</td>"; 
  35. if (($i==7%$first || ($i+$first)%7==0) && $i<$count){ 
  36. $html .= "</tr>n<tr>"; 
  37. } 
  38. } 
  39. $count = 7-$count%7; 
  40. if ($count<7){ 
  41. for ($i=0; $i<$count; $i++){ 
  42. $html .= "<td></td>"; 
  43. } 
  44. } 
  45. $html .= "</tr>n"; 
  46. $html .= "</table>n"; 
  47. return $html; 
  48. } 
  49. } 
  50. $calendar = new calendar(); 
  51. $calendar->set(time()); 
  52. echo $calendar->html(); 
  53.  

出处:http://www.phpfensi.com/php/20131211/931.html


相关教程