简单的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 .= 上一月{$this->y}年 {$this->m}月下一月
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 .= $i ;
if (($i==7%$first || ($i+$first)%7==0) && $i$html .=
n;
}
}
$count = 7-$count%7;
if ($countfor ($i=0; $i$html .= ;
}
}
$html .=
n;
$html .=
n;
return $html;
}
}$calendar = new calendar();
$calendar->set(time());
echo $calendar->html();
http://www.bkjia.com/phpjc/444926.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/444926.htmltecharticle本文章主要是一个php初学者写的原创的php日历控件 ,可以显示当前日期与今天是星期几,是否为闰年, 可自动选择上一年或下一年,月份日...
