Home  >  Article  >  php教程  >  简单的php日历类控件代码实例

简单的php日历类控件代码实例

WBOY
WBOYOriginal
2016-06-13 11:23:431088browse

本文章主要是一个php初学者写的原创的php日历控件 ,可以显示当前日期与今天是星期几,是否为闰年, 可自动选择上一年或下一年,月份日期也是一样的。

简单的php教程日历类控件代码实例
/*
本文章主要是一个php初学者写的原创的php日历控件 ,可以显示当前日期与今天是星期几,是否为闰年, 可自动选择上一年或下一年,月份日期也是一样的。
*/
date_default_timezone_set("Etc/GMT-8");

class Calendar{

var $T = array();
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');
var $Y,$M,$D;

function set($time){
$this->T = getdate($time);
$this->Y = $this->T['year'];
$this->M = $this->T['mon'];
$this->D = date('d',$time);
}

function isRun(){
return ($this->Y%400==0 || ($this->Y%4==0 && $this->Y%100==0)) ? 1 : 0;
}

function first(){
$time = mktime(0,0,0,$this->M,1,$this->Y);
$time = getdate($time);
return $time['wday'];
}

function html(){
$isRun = $this->isRun();
$this->datesOFmonth[2] = $isRun==1 ? 29: 28;
$html .= "

n";
$html .= "n";
$html .= "n";
$html .= "n";
$first = $this->first();
for($i=0; $i$html .= "";
}
$count = $this->datesOFmonth[$this->M]+$first;
for ($i=1; $idatesOFmonth[$this->M]; $i++){
$style = $i==$this->D ? ' style="color:red;font-weight:bold;"' : '' ;
$html .= "";
if (($i==7%$first || ($i+$first)%7==0) && $i$html .= "n";
}
}
$count = 7-$count%7;
if ($countfor ($i=0; $i$html .= "";
}
}
$html .= "n";
$html .= "
上一月 {$this->Y}年 {$this->M}月 下一月
星期天 星期一 星期二 星期三 星期四 星期五 星期六
$i
n";
return $html;
}
}

$calendar = new Calendar();
$calendar->set(time());
echo $calendar->html();


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn