Chinaunix首页 | 论坛 | 博客
  • 博客访问: 631164
  • 博文数量: 87
  • 博客积分: 3399
  • 博客等级: 中校
  • 技术积分: 1422
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-17 21:20
文章分类

全部博文(87)

文章存档

2013年(1)

2012年(51)

2011年(33)

2010年(2)

分类: 系统运维

2011-11-01 16:45:53

  1. <?php
  2. class Calendar{
  3. var $YEAR,$MONTH,$DAY;
  4. var $COLOR_TODAY = "lightgray"; //当前日期的背景色

  5. var $COLOR_THIS_MONTH = "lightgray"; //当前月的背景色

  6. var $COLOR_THIS_YEAR = "lightgray"; //当前年的背景色

  7. var $NUMS_YEAR = 1; //年份下拉表里可以显示的年份数目


  8. var $WEEK=array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");
  9. var $_MONTH=array(
  10. "01"=>"一月",
  11. "02"=>"二月",
  12. "03"=>"三月",
  13. "04"=>"四月",
  14. "05"=>"五月",
  15. "06"=>"六月",
  16. "07"=>"七月",
  17. "08"=>"八月",
  18. "09"=>"九月",
  19. "10"=>"十月",
  20. "11"=>"十一月",
  21. "12"=>"十二月"
  22. );
  23. function setYear($year){
  24.     $this->YEAR=$year;
  25. }
  26. //获得年份

  27. function getYear(){
  28.     return $this->YEAR;
  29. }
  30. //设置月份

  31. function setMonth($month){
  32.     $this->MONTH=$month;
  33. }
  34. //获得月份

  35. function getMonth(){
  36.     return $this->MONTH;
  37. }
  38. //设置日期

  39. function setDay($day){
  40.     $this->DAY=$day;
  41. }
  42. //获得日期

  43. function getDay(){
  44.     return $this->DAY;
  45. }
  46. //获得方法内指定的日期的星期数 0(表示星期天)到 6(表示星期六)

  47. function getWeek($year,$month,$day){
  48.         $week=date("w",mktime(0,0,0,$month,$day,$year));//获得星期

  49.         return $week;//获得星期

  50.         }
  51. //为$YEAR,$MONTH,$DAY赋值

  52. function _env(){
  53.     if(isset($_POST['month'])){//有指定月

  54.         $month=$_POST['month'];
  55.         }else{
  56.             $month=date("m");//默认为本月

  57.         }
  58.         if(isset($_POST['year'])){//有指年

  59.             $year=$_POST['year'];
  60.         }else{
  61.             $year=date("Y");//默认为本年

  62.         }
  63.     $this->setYear($year);
  64.     $this->setMonth($month);
  65.     $this->setDay(date("d"));
  66.     }
  67. //打印日历

  68. function out(){
  69.     $this->_env();
  70.     $week=$this->getWeek($this->YEAR,$this->MONTH,$this->DAY);//获得日期为星期几 (例如今天为2011-10-31,星期一)

  71.     $fweek=$this->getWeek($this->YEAR,$this->MONTH,1);//获得此月第一天为星期几

  72.     //echo "


  73.     echo "";
  74.         for($Tmpa=0;$Tmpa<count($this->WEEK);$Tmpa++){//打印星期标头

  75.             echo "
  76. ";
  77.         }
  78.             echo "
  79. ";
  80.             for($Tmpc=0;$Tmpc<$fweek;$Tmpc++){
  81.                     echo "
  82. ";
  83.                 }
  84.           for($Tmpb=1;$Tmpb<=date("t",mktime(0,0,0,$this->MONTH,$this->DAY,$this->YEAR));$Tmpb++){//打印所有日期

  85.             $Tmpb=sprintf("%02d",$Tmpb);
  86.             if((strcmp($Tmpb,$this->DAY)==0) && ($this->MONTH == date("m")) && ($this->YEAR == date("Y")) ){//获得当前日期,做标记

  87.                 $flag=" bgcolor='$this->COLOR_TODAY'";
  88.             }else{
  89.                 $flag=" bgcolor='white'";
  90.             }
  91.             if((strcmp($this->getWeek($this->YEAR,$this->MONTH,$Tmpb),0)==0) && (1==$Tmpb)){ //第一天是星期日则不用加


  92.                 echo "
  93. ";//星期日则换行,添加行首

  94.             }else if(strcmp($this->getWeek($this->YEAR,$this->MONTH,$Tmpb),0)==0){
  95.                 echo "
  96. ";//星期日则换行,添加行首

  97.             }else if(strcmp($this->getWeek($this->YEAR,$this->MONTH,$Tmpb),6)==0){
  98.                 echo "
  99. ";//星期六为行尾

  100.             }else{
  101.                 echo "
  102. ";
  103.             }
  104.          
  105.     }//for($Tmpb=1;$Tmpb<=date("t",mktime(0,0,0,$this->MONTH,$this->DAY,$this->YEAR));$Tmpb++)

  106.     //最后一天是星期六不用再加


  107.     if(strcmp($this->getWeek($this->YEAR,$this->MONTH,date("t",mktime(0,0,0,$this->MONTH,$this->DAY,$this->YEAR))),6)==0)
  108.         echo "

  109.     

  110.     月份: 年份:
  111.             
  112. ".$this->WEEK[$Tmpa]."
    $Tmpb
    $Tmpb $Tmpb
    $Tmpb
    "
    ;
  113.     else
  114.         echo "
  115. ";
  116.  }//out();

  117. }//class Calendar

  118. $d = new Calendar();
  119. $d->out();
  120. ?>
阅读(6442) | 评论(0) | 转发(0) |
0

上一篇:心跳包

下一篇:php 网站计数器

给主人留下些什么吧!~~