php专区

 首页 > php专区 > PHP应用 > php类库 > 非常简单的日历类 - php类库

非常简单的日历类 - php类库

分享到:
【字体:大 中 小】
导读:
          date_default_timezone_set(etc gmt-8);classcalendar{var$t=array();var$datesofmonth=array( 39;1 39;= 39;31 39;, 39;2 39;=...

非常简单的日历类

  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 .= "n"; 
  24. $html .= "上一月{$this->y}年 {$this->m}月下一月n"; 
  25. $html .= "星期天星期一星期二111cn.net星期三星期四星期五星期六n"; 
  26. $html .= "n"; 
  27. $first = $this->first(); 
  28. for($i=0; $i<$first; $i++){ 
  29. $html .= ""; 
  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 .= "$i"; 
  35. if (($i==7%$first || ($i+$first)%7==0) && $i<$count){ 
  36. $html .= "n"; 
  37. } 
  38. } 
  39. $count = 7-$count%7; 
  40. if ($count<7){ 
  41. for ($i=0; $i<$count; $i++){ 
  42. $html .= ""; 
  43. } 
  44. } 
  45. $html .= "n"; 
  46. $html .= "n"; 
  47. return $html; 
  48. } 
  49. } 
  50. $calendar = new calendar(); 
  51. $calendar->set(time()); 
  52. echo $calendar->html(); 
分享到:
PHP分页类 - php类库
PHP分页类  
php数字分页类的代码 - php类库
php数字分页类的代码 下面是一款php数字分页类的代码,己经封装好了的代码,需要的朋友可以参考使用一下,分页的主要原理就是获取当前页面,再判断一页多少条记录相除,得出总记录,就这么简单了。 function getnavhtml($pagenum,$pagesize,$rowcount,$navurl){   $pagecount = (int)($...
  •         php迷,一个php技术的分享社区,专属您自己的技术摘抄本、收藏夹。
  • 在这里……