Home > Backend Development > PHP Tutorial > PHP complete calendar class (CLASS)_PHP tutorial

PHP complete calendar class (CLASS)_PHP tutorial

WBOY
Release: 2016-07-21 15:59:56
Original
795 people have browsed it

Copy code The code is as follows:

class Calendar{
/*
* www.jb51.net修正版
*/
var $YEAR,$MONTH,$DAY;
var $WEEK=array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");
var $_MONTH=array(
"01"=>"一月", 
"02"=>"二月", 
"03"=>"三月", 
"04"=>"四月", 
"05"=>"五月", 
"06"=>"六月", 
"07"=>"七月", 
"08"=>"八月", 
"09"=>"九月", 
"10"=>"十月", 
"11"=>"十一月", 
"12"=>"十二月" 
); 
//设置年份 
function setYear($year){ 
$this->YEAR=$year; 

//获得年份 
function getYear(){ 
return $this->YEAR; 

//设置月份 
function setMonth($month){ 
$this->MONTH=$month; 

//获得月份 
function getMonth(){ 
return $this->MONTH; 

//设置日期 
function setDay($day){ 
$this->DAY=$day; 

//获得日期 
function getDay(){ 
return $this->DAY; 

//打印日历 
function OUT(){ 
$this->_env(); 
$week=$this->getWeek($this->YEAR,$this->MONTH,$this->DAY);//获得日期为星期几 (例如今天为2003-07-18,星期五) 
$fweek=$this->getWeek($this->YEAR,$this->MONTH,1); //获得此月第一天为星期几 
echo "
  
 
"; 
for($Tmpa=0;$TmpaWEEK);$Tmpa++){//打印星期标头 
echo "
"; //补充打印 
for($Tmpc=0;$Tmpc<$fweek;$Tmpc++){ 
echo "
".$this->WEEK[$Tmpa]; 

for($Tmpb=1;$Tmpb<=date("t",mktime(0,0,0,$this->MONTH,$this->DAY,$this->YEAR));$Tmpb++){//打印所有日期 
if(strcmp($Tmpb,$this->DAY)==0){ //获得当前日期,做标记 
$flag=" bgcolor='#ff0000'"; 
}else{ 
$flag=' bgcolor=#ffffff'; 

if($Tmpb==1){ 
echo "
"; 


if(strcmp($this->getWeek($this->YEAR,$this->MONTH,$Tmpb),0)==0){ 
echo "
$Tmpb"; 
}else{ 
echo "
$Tmpb"; 


echo "
";
}
//Get the week number of the date specified in the method
function getWeek($year,$month,$day){
$week=date("w",mktime (0,0,0,$month,$day,$year));//Get the week
return $week;//Get the week
}
function _env(){
if( isset($_POST["month"]){ //Specified month
$month=$_POST["month"];
}else{
$month=date("m"); //The default is this month
}
if(isset($_POST["year"])){ //The year is specified
$year=$_POST["year"];
} else{
$year=date("Y"); //The default is this year
}
$this->setYear($year);
$this->setMonth($ month);
$this->setDay(date("d"));
}
}
$D=new Calendar;
$D->OUT();
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/317183.htmlTechArticleCopy the code as follows: ?php classCalendar{ /* *www.jb51.net revised version*/ var$YEAR ,$MONTH,$DAY; var$WEEK=array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template