ag旗舰厅官网_ag旗舰厅下载客户端

热门关键词: ag旗舰厅官网,ag旗舰厅下载客户端

计算机网络

当前位置:ag旗舰厅官网 > 计算机网络 > PHP实现的简单日历类,非常简单的日历类

PHP实现的简单日历类,非常简单的日历类

来源:http://www.pedaLyourcycLe.com 作者:ag旗舰厅官网 时间:2019-10-03 14:56

非常简单的日历类

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

 代码如下

具体实现代码如下:

date_default_timezone_set("etc/gmt-8");

复制代码 代码如下:

class calendar{

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 .= "<table style='border:solid 1px black;'>n";
$html .= "<tr><th><a href=''>上一月</a></th><th colspan='5'>{$this->y}年 {$this->m}月</th><th><a href=''>下一月</a></th><tr>n";
$html .= "<tr><td>星期天</td><td>星期一</td><td>星期二</td>jb51.net<td>星期三</td><td>星期四</td><td>星期五</td><td>星期六</td></tr>n";
$html .= "<tr>n";
$first = $this->first();
for($i=0; $i<$first; $i++){
$html .= "<td></td>";
}
$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 .= "<td align='center'{$style}>$i</td>";
if (($i==7%$first || ($i+$first)%7==0) && $i<$count){
$html .= "</tr>n<tr>";
}
}
$count = 7-$count%7;
if ($count<7){
for ($i=0; $i<$count; $i++){
$html .= "<td></td>";
}
}
$html .= "</tr>n";
$html .= "</table>n";
return $html;
}
}
$calendar = new calendar();
$calendar->set(time());
echo $calendar->html();

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;

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

function set($time){
$this->t = getdate($time);
$this->y = $this->t['year'];
$this->m = $this->t['mon'];
$this->d = date('d',$time);
}

您可能感兴趣的文章:

  • php+javascript的日历控件
  • 用 php 编写的日历
  • php下实现农历日历的代码
  • 教大家制作简单的php日历
  • php+mysql+jquery实现日历签到功能
  • PHP完整的日历类(CLASS)
  • PHP输出日历表代码实例
  • 基于ThinkPHP实现的日历功能实例详解
  • php实现的日历程序
  • 分享3个php获取日历的函数
  • PHP实现的日历功能示例

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 .= "<table style='border:solid 1px black;'> ";
$html .= "<tr><th><a href=''>上一月</a></th><th colspan='5'>{$this->y}年 {$this->m}月</th><th><a href=''>下一月</a></th><tr> ";
$html .= "<tr><td>星期天</td><td>星期一</td><td>星期二</td>111cn.net<td>星期三</td><td>星期四</td><td>星期五</td><td>星期六</td></tr> ";
$html .= "<tr> ";
$first = $this->first();
for($i=0; $i<$first; $i++){
$html .= "<td></td>";
}
$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 .= "<td align='center'{$style}>$i</td>";
if (($i==7%$first || ($i+$first)%7==0) && $i<$count){
$html .= "</tr> <tr>";
}
}
$count = 7-$count%7;
if ($count<7){
for ($i=0; $i<$count; $i++){
$html .= "<td></td>";
}
}
$html .= "</tr> ";
$html .= "</table> ";
return $html;
}
}

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

本文由ag旗舰厅官网发布于计算机网络,转载请注明出处:PHP实现的简单日历类,非常简单的日历类

关键词: