用户名:
密 码: 记住
您当前的位置:首页 > 网络编程 > php教程

非常简单的日历类

时间:2015-01-23  来源:西部数据  作者:西部数据
  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. function isrun(){ 
  12. return ($this->y%400==0 || ($this->y%4==0 && $this->y%100==0)) ? 1 : 0; 
  13. function first(){ 
  14. $time = mktime(0,0,0,$this->m,1,$this->y); 
  15. $time = getdate($time); 
  16. return $time['wday']; 
  17. function html(){ 
  18. $isrun = $this->isrun(); 
  19. $this->datesofmonth[2] = $isrun==1 ? 29: 28; 
  20. $html .= "<table style='border:solid 1px black;'>n"
  21. $html .= "<tr><th><a href=''>上一月</a></th><th colspan='5'>{$this->y}年 {$this->m}月</th><th><a href=''>下一月</a></th><tr>n"
  22. $html .= "<tr><td>星期天</td><td>星期一</td><td>星期二</td>111cn.net<td>星期三</td><td>星期四</td><td>星期五</td><td>星期六</td></tr>n"
  23. $html .= "<tr>n"
  24. $first = $this->first(); 
  25. for($i=0; $i<$first$i++){ 
  26. $html .= "<td></td>"
  27. $count = $this->datesofmonth[$this->m]+$first
  28. for ($i=1; $i<= $this->datesofmonth[$this->m]; $i++){ 
  29. $style = $i==$this->d ? ' style="color:red;font-weight:bold;"' : '' ; 
  30. $html .= "<td align='center'{$style}>$i</td>"
  31. if (($i==7%$first || ($i+$first)%7==0) && $i<$count){ 
  32. $html .= "</tr>n<tr>"
  33. $count = 7-$count%7; 
  34. if ($count<7){ 
  35. for ($i=0; $i<$count$i++){ 
  36. $html .= "<td></td>"
  37. $html .= "</tr>n"
  38. $html .= "</table>n"
  39. return $html
  40. $calendar = new calendar(); 
  41. $calendar->set(time()); 
  42. echo $calendar->html(); 
来顶一下
返回首页
返回首页
推荐资讯
WiFi太不安全:7岁女孩11分钟内入侵公共网络 WiFi太不安全:7岁女孩11分钟内入侵近期刚刚发布研究说WiFi网络能获得人们手机里多少私人信息,
不服跑个分?人工智能也出现“刷分”乱象 不服跑个分?人工智能也出现“刷分2014年,人工智能领域突然爆发,成为了科研和科技创业的热门
相关文章
栏目更新
栏目热门