php日曆類

來源:互聯網
上載者:User

<?php
class Calendar{
/*
 *  日曆
 *
 *   @作者:sports98
 *   Email:flyruns@hotmail.com
 *   @版本:V1.0
 */
  var $YEAR,$MONTH,$DAY;
  var $WEEK=array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");
  var $_MONTH=array(
      "01"=>"一月",
      "02"=>"二月",
      "03"=>"三月",
      "04"=>"四月",
      "05"=>"五月",
      "06"=>"六月",
      "07"=>"七月",
      "08"=>"八月",
      "09"=>"九月",
      "10"=>"十月",
      "11"=>"十一月",
      "12"=>"十二月"
    );
  //設定年份
  function setYear($year){
    $this->YEAR=$year;
  }
  //獲得年份
  function getYear(){
    return $this->YEAR;
  }
  //設定月份
  function setMonth($month){
    $this->MONTH=$month;
  }
  //獲得月份
  function getMonth(){
    return $this->MONTH;
  }
  //設定日期
  function setDay($day){
    $this->DAY=$day;
  }
  //獲得日期
  function getDay(){
    return $this->DAY;
  }
  //列印日曆
  function OUT(){
    $this->_env();
    $week=$this->getWeek($this->YEAR,$this->MONTH,$this->DAY);//獲得日期為星期幾 (例如今天為2003-07-18,星期五)
    $fweek=$this->getWeek($this->YEAR,$this->MONTH,1);//獲得此月第一天為星期幾
    echo "<div style=\"margin:0;border:1 solid black;width:300;font:9pt\">
      <form action=$_SERVER[PHP_SELF] method=\"post\" style=\"margin:0\">
      <select name=\"month\" onchange=\"this.form.submit();\">";
    for($ttmpa=1;$ttmpa<13;$ttmpa++){//列印12個月
      $ttmpb=sprintf("%02d",$ttmpa);
      if(strcmp($ttmpb,$this->MONTH)==0){
        $select="selected style=\"background-color:#c0c0c0\"";
      }else{
        $select="";
      }
      echo "<option value=\"$ttmpb\" $select>".$this->_MONTH[$ttmpb]."</option>\r\n";
    }
    echo "  </select> <select name=\"year\" onchange=\"this.form.submit();\">";//列印年份,前後10年
    for($ctmpa=$this->YEAR-10;$ctmpa<$this->YEAR+10;$ctmpa++){
      if($ctmpa>2037){
        break;
      }
      if($ctmpa<1970){
        continue;
      }
      if(strcmp($ctmpa,$this->YEAR)==0){
        $select="selected style=\"background-color:#c0c0c0\"";
      }else{
        $select="";
      }
      echo "<option value=\"$ctmpa\" $select>$ctmpa</option>\r\n";
    }
    echo   "</select>
      </form>
      <table border=0 align=center>";
    for($Tmpa=0;$Tmpa<count($this->WEEK);$Tmpa++){//列印星期標題
      echo "<td>".$this->WEEK[$Tmpa];
    }
    for($Tmpb=1;$Tmpb<=date("t",mktime(0,0,0,$this->MONTH,$this->DAY,$this->YEAR));$Tmpb++){//列印所有日期
      if(strcmp($Tmpb,$this->DAY)==0){  //獲得當前日期,做標記
        $flag=" bgcolor='#ff0000'";
      }else{
        $flag=' bgcolor=#ffffff';
      }
      if($Tmpb==1){    
        echo "<tr>";    //補充列印
        for($Tmpc=0;$Tmpc<$fweek;$Tmpc++){
          echo "<td>";
        }
      }
      if(strcmp($this->getWeek($this->YEAR,$this->MONTH,$Tmpb),0)==0){
        echo "<tr><td align=center $flag>$Tmpb";
      }else{
        echo "<td align=center $flag>$Tmpb";
      }
    }
    echo "</table></div>";
  }
  //獲得方法內指定的日期的星期數
  function getWeek($year,$month,$day){
    $week=date("w",mktime(0,0,0,$month,$day,$year));//獲得星期
    return $week;//獲得星期
  }
  function _env(){
    if(isset($_POST[month])){  //有指定月
      $month=$_POST[month];
    }else{
      $month=date("m");  //預設為本月
    }
    if(isset($_POST[year])){  //有指年
      $year=$_POST[year];
    }else{
      $year=date("Y");  //預設為本年
    }
  $this->setYear($year);
  $this->setMonth($month);
  $this->setDay(date("d"));
  }
}
$D=new Calendar;
$D->OUT();
?>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.