zoukankan      html  css  js  c++  java
  • 【转】PHP日历

    <?php
    class Calendar
    {
    	var $T = array();
    	var $MonthDays = 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');
    	var $Week=array('0'=>'日','1'=>'一','2'=>'二','3'=>'三','4'=>'四','5'=>'五','6'=>'六');
    	var $Y,$M,$D;
    	function __construct()
    	{
    		date_default_timezone_set ('prc');
    		$this->Y=isset($_GET['year']) ? $_GET['year'] : date("Y");
    		$this->M=isset($_GET['month']) ? $_GET['month'] : date("m");
    
    /*		$this->Y=date('Y');
    		$this->M=date('m');
    */		$this->D=date('j');
    	}
    	function SetTime($Y,$M,$D)
    	{
    		$this->Y=$Y;
    		$this->M=$M;
    		$this->D=$D;
    	}
    	function IsLeapYear()
    	{
    		return ($this->Y%400==0 || ($this->Y%4==0 && $this->Y%100<>0)) ? 1 : 0;
    	}
    
    	function GetMouFirDayWeek()
    	{
    		$time = mktime(0,0,0,$this->M,1,$this->Y);
    		$time = getdate($time);
    		return $time['wday'];
    	}
    	function ShowCalendar()
    	{
    		$IsLeapY = $this->IsLeapYear();
    		$this->datesOFmonth[2] = $IsLeapY==1 ? 29: 28;
    		?>
    		<style type="text/css">
    			.calendartb 
    			{
    				border-collapse: collapse;
    				border-spacing: 0px;
    				empty-cells: show;
    				font-family: microsoft yahei;
    			}
    			td
    			{
    				font-size: 12px;
    				text-align: center;
    				padding:2px 5px 2px 6px;
    			}
    			.calendartb a
    			{
    				text-decoration: none;
    			}
    			.calendartb a:hover
    			{
    				color:rgb(255,0,0);
    			}
    			</style>
    		<meta charset="utf-8">
    		<div style="border:1px solid rgb(0,0,0);180px">
    			<table class="calendartb "style="180px;border-bottom:1px solid rgb(0,0,0);">
    				<tr>
    					<td>
    						<a href="<?php echo $this->PreYear($this->Y,$this->M);?>"><<</a>
    					</td>
    					<td>
    						<a href="<?php echo $this->PreMouth($this->Y,$this->M);?>"><</a>
    					</td>
    					<td>
    						<a href="?"style="color:rgb(0,0,0);"><?php echo $this->Y."年".$this->M."月";?></a>
    					</td>
    					<td>
    						<a href="<?php echo $this->NexMouth($this->Y,$this->M);?>">></a>
    					</td>
    					<td>
    						<a href="<?php echo $this->NexYear($this->Y,$this->M);?>">>></a>
    					</td>
    				</tr>
    			</table>
    			<table class="calendartb ">
    				<tr>
    					<td>日</td>
    					<td>一</td>
    					<td>二</td>
    					<td>三</td>
    					<td>四</td>
    					<td>五</td>
    					<td>六</td>
    				</tr>
    				<tr>
    					<?php
    						for ($s=0;$s<$this->GetMouFirDayWeek();$s++)
    							echo '<td></td>';
    						for ($i=1;$i<=$this->MonthDays[$this->M];$i++)
    						{
    							if (($i+$s)%7==1)
    								echo '</tr><tr>';
    							if ($i==$this->D)
    								echo "<td style="color:rgb(255,0,0);font-weight:bold;">$i</td>";
    							else
    								echo "<td>$i</td>";
    						}
    					?>
    				</tr>
    			</table>
    		</div>
    		<?php
    	}
    	
    	private function PreMouth($thisY,$thisM)
    	{
    		if ($thisM==1)
    		{
    			$thisY=$thisY-1;
    			$thisM=12;
    		}
    		else
    		{
    			$thisM=$thisM-1;
    		}
    		return '?year='.$thisY.'&month='.$thisM;
    	}
    	private function NexMouth($thisY,$thisM)
    	{
    		if ($thisM==12)
    		{
    			$thisY=$thisY+1;
    			$thisM=1;
    		}
    		else
    		{
    			$thisM=$thisM+1;
    		}
    		return '?year='.$thisY.'&month='.$thisM;
    	}
    	private function PreYear($thisY,$thisM)
    	{
    		$thisY=$thisY-1;
    		return '?year='.$thisY.'&month='.$thisM;
    	}
    	private function NexYear($thisY,$thisM)
    	{
    		$thisY=$thisY+1;
    		return '?year='.$thisY.'&month='.$thisM;
    	}
    }
    ?>
  • 相关阅读:
    @EnableCaching缓存
    totastmessage 触发事件后浮框消失的方法
    JavaScript的类型自动转换样例集合处
    [译]bootstrap-select (selectpicker)方法
    通过使用CSS字体阴影效果解决hover图片时显示文字看不清的问题
    [Java]求文件大小并保留两位小数(文件大小是一个长整型数单位是Byte)
    PHP多进程编程(2):管道通信
    PHP多进程编程(一)
    如何解决PHP里大量数据循环时内存耗尽的问题
    推荐!国外程序员整理的 PHP 资源大全
  • 原文地址:https://www.cnblogs.com/rlm0909/p/3412436.html
Copyright © 2011-2022 走看看