php简单的日历代码,PHP实现的简单日历类

本文实例讲述了PHP实现的简单日历类。分享给大家供大家参考。

具体实现代码如下:

date_default_timezone_set("etc/gmt-8");

header("Content-type: text/html; charset=utf-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 .= "

$html .= "

上一月{$this->y}年 {$this->m}月 下一月n";

$html .= "

星期天星期一星期二jb51.net星期三星期四星期五星期六n";

$html .= "

n";

$first = $this->first();

for($i=0; $i

$html .= "

";

}

$count = $this->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";

if (($i==7%$first || ($i+$first)%7==0) && $i

$html .= "

n";

}

}

$count = 7-$count%7;

if ($count<7){

for ($i=0; $i

$html .= "

";

}

}

$html .= "

n";

$html .= "

n";

return $html;

}

}

$calendar = new calendar();

$calendar->set(time());

echo $calendar->html();

希望本文所述对大家的php程序设计有所帮助。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值