Affichage de tous les codes

1, Affichage du répertoire du projet :

微信图片_20180313161104.png

2, Affichage de tous les codes :

calendar.php:

     
getLyTime(); // echo $convert.'对应的农历时间:'.$time; } //php日历 //1.date()函数获取当前的年月 $year=isset($_GET["y"])?$_GET["y"]:date("Y"); $mon=isset($_GET["m"])?$_GET["m"]:date("m"); //2.mktime()函数的使用,获取当前月的天数及当月1号的星期 $day=date("t",mktime(0,0,0,$mon,1,$year));//当前月的天数 31 $w=date("w",mktime(0,0,0,$mon,1,$year));//当月1号的星期几 4 //3.输出日历的头部信息 echo"
"; echo""; echo"

{$year}年{$mon}月

"; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; //4.遍历输出日历 $d=1; while($d<=$day){ echo""; for($i=1;$i<=7;$i++){//循环输出7天信息 if($d<=$day&&($w<$i||$d!=1)){ //'2014-10-1'(传入这样一个字符串)$year-$month-$d $ymd=$year.'-'.$mon.'-'.$d; echo ""; $d++; }else{ echo""; } } } //5.处理上下月,上下年的信息 $prey=$nexty=$year; $prem=$nextm=$mon; if($prem<=1){ $prem=12; $prey--; }else{ $prem--; } if($nextm>=12){ $nextm=1; $nexty++; }else{ $nextm++; } $prey=$year-1;//上一年 $nexty=$year+1;//下一年 //超链接 echo ""; echo ""; echo "
{$d}
"; echo"<< "; echo "{$year}年 "; echo ">> "; echo" "; echo"< "; echo "{$mon}月 "; echo ">"; echo "
"; echo "
$convert 对应的农历时间:$time
"; echo "
"; echo "
"; ?>

Convert.class.php:

curData=$curData; }else{ $this->curData=date('Y-n-j'); } $this->init(); } public function init(){ $basedate='1900-2-1';//参照日期 $timezone='PRC'; $datetime= new DateTime($basedate, new DateTimeZone($timezone)); $curTime=new DateTime($this->curData, new DateTimeZone($timezone)); $offset = ($curTime->format('U') - $datetime->format('U'))/86400; //相差的天数 $offset=ceil($offset); $this->difDay=$offset; $offset+=1;//只能使用ceil,不能使用intval或者是floor,因为1900-1-31为正月初一,故需要加1 for($i=1900; $i<2050 && $offset>0; $i++){ $temp = $this->getYearDays($i); //计算i年有多少天 $offset -= $temp ; $this->difmonth+=12; //判断该年否存在闰月 if($this->leapMonth($i)>0){ $this->difmonth+=1; } } if($offset<0){ $offset += $temp; $i--; $this->difmonth-=12; } if($this->leapMonth($i)>0){ $this->difmonth-=1; } $this->ylDays=$offset; //此时$offset代表是农历该年的第多少天 $this->ylYeal=$i;//农历哪一年 //计算月份,依次减去1~12月份的天数,直到offset小于下个月的天数 $curMonthDays=$this->monthDays($this->ylYeal,1); //判断是否该年是否存在闰月以及闰月的天数 $this->leap=$this->leapMonth($this->ylYeal); if($this->leap !=0){ $this->leapDays=$this->leapDays($this->ylYeal); } for($i=1;$i<13 && $curMonthDays<$offset;$curMonthDays=$this->monthDays($this->ylYeal,++$i)){ if($this->leap == $i){ //闰月 if($offset>$this->leapDays){ --$i; $offset-=$this->leapDays; $this->difmonth+=1; }else{ break; } }else{ $offset-=$curMonthDays; $this->difmonth+=1; } } $this->ylMonth=$i; $this->yldate=$offset; } /** *计算农历y年有多少天 **/ public function getYearDays($y){ $sum = 348;//12*29=348,不考虑小月的情况下 for($i=0x8000; $i>=0x10; $i>>=1){ $sum += ($this->dataInfo[$y-1900] & $i)? 1: 0; } return($sum+$this->leapDays($y)); } /** *获取某一年闰月的天数 **/ public function leapDays($y){ if($this->leapMonth($y)){ return(($this->dataInfo[$y-1900] & 0x10000)? 30: 29); } else { return(0); } } /** *计算哪一月为闰月 */ public function leapMonth($y){ return ($this->dataInfo[$y-1900] & 0xf); } /** *计算农历y年m月有多少天 */ public function monthDays($y,$m){ return (($this->dataInfo[$y-1900] & (0x10000>>$m))? 30: 29 ); } public function getLyTime(){ $tmp=array('初','一','二','三','四','五','六','七','八','九','十','廿'); $dateStr=''; if($this->ylMonth>10){ $m2=intval($this->ylMonth -10); //十位 $dateStr='十'.$tmp[$m2].'月'; }elseif($this->ylMonth==1){ $dateStr='正月'; }else{ $dateStr=$tmp[$this->ylMonth].'月'; } if($this->yldate <11){ $dateStr.='初'.$tmp[$this->yldate]; }else{ $m1=intval($this->yldate / 10); if( $m1 !=3){ $dateStr.=($m1==1)?'十':'廿'; $m2=$this->yldate % 10; if($m2==0){ $dateStr.='十'; }else{ $dateStr.=$tmp[$m2]; } }else{ $dateStr.='三十'; } } return $dateStr; } /** *获取该年对于的天干地支年 **/ public function getYGanZhi(){ $gan=$this->tianGan[($this->ylYeal-4) % 10]; $zhi=$this->diZhi[($this->ylYeal-4) % 12]; return $gan.$zhi.'年'; } /** *获取该年对于的天干地支月 **/ public function getMGanZhi(){ $gan=$this->tianGan[($this->difmonth+3) % 10]; $zhi=$this->diZhi[($this->difmonth+1) % 12]; return $gan.$zhi.'月'; } /** *获取该年对于的天干地支日 **/ public function getDGanZhi(){ $gan=$this->tianGan[$this->difDay % 10]; $zhi=$this->diZhi[($this->difDay+4) % 12]; return $gan.$zhi.'日'; } }


Formation continue
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!