本文实例讲述了PHP实现的简单日历类。分享给大家供大家参考。
具体实现代码如下:
代码如下:
'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,$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}月 | 下一月 | ||||
---|---|---|---|---|---|
datesofmonth[$this->m]+$first; for ($i=1; $i<= $this->datesofmonth[$this->m]; $i++){ $style = $i==$this->d ? ' style="color:red;font-weight:bold;"' : '' ; $html .= " | $i | set(time()); echo $calendar->html();