Home > Backend Development > PHP Tutorial > Two php date control class instances, php date class instances_PHP tutorial

Two php date control class instances, php date class instances_PHP tutorial

WBOY
Release: 2016-07-13 10:12:06
Original
1819 people have browsed it

Two php date control class instances, php date class instances

The examples in this article describe two PHP date control classes. Share it with everyone for your reference. The specific analysis is as follows:

Due to work needs, I found two time and date controls. This does not require JS and only needs to be implemented in PHP. Because it requires a reference query operation, interested friends can refer to it. I use the second one myself, so the second one is used. I have made modifications myself.

Example 1, the code is as follows:

Copy code The code is as follows:
<?php
class Calendar
{
var $month;
var $year;

function __construct($year,$month)
{
$this->year=$year;
  $this->month=$month;
 }
 
 function endday()
 {
  $daydate=date("d",mktime(0,0,0,$this->month,35,$this->year));
  $endday=35-$daydate;
  return $endday;
 }
 
 function oneday_week()
 {
  $oneday_week=date("w",mktime(0,0,0,$this->month,1,$this->year));
  return $oneday_week;
 }
 
 function title_link()
 {
  if(!isset($this->month) && !isset($this->year))
  {
   $this->year  = date("Y");
   $this->month = date("m");
        }
  
  $lastmonth=$this->month-1;
  $nextmonth=$this->month+1;
  $lastyear=$this->year;
  $nextyear=$this->year;
 
        if($this->month <= 1)
{
$lastmonth=12;
$nextmonth=$this->month+1;
   $lastyear=$this->year-1;
   $nextyear=$this->year;
  }
        elseif ($this->month >= 12) 
        {
         $lastmonth=$this->month-1;
         $nextmonth=1;
   $lastyear=$this->year;
   $nextyear=$this->year+1;
        }
 
        $str ="";
  $str.="
".$this->year."--".$this->month."
";
  $str.="";
  return $str;
 }
 
 function Show_Calendar()
 {
        echo "".$this->title_link()."";
        $weekarray=array("日","一","二","三","四","五","六");
        
        for($k=0;$k<=6;$k++)
{
echo "";
        }
        echo "";
        
        for($i=0;$i<=5;$i++)
        {
         echo "";
         for($j=1;$j<=7;$j++)
{
$math=( $j - $this->oneday_week() ) + 7 * $i;
    
          echo "";
                                                                    echo "";
          }
echo "
".$weekarray[$k]."
";
    
          if($math <= $this->endday() and $math>=1)
     {
   echo $math;
     }
    
         echo "
";
}
}
$calendar=new Calendar($_GET['year'],$_GET['month']);
$calendar->month=$_GET['month'];
$calendar->year=$_GET['year'];
$calendar->Show_Calendar();
?>
Example 2, the code is as follows:

Copy code The code is as follows:
header("content-type:text/html;charset=utf-8");
?>

 


if(!emptyempty($_GET)){
    $year = isset($_GET['year'])?$_GET['year']:date('y');
    $month = isset($_GET['month'])?$_GET['month']:date('m');
 $day = isset($_GET['day'])?$_GET['day']:date('d');
}
if(emptyempty($year)){
    $year = date('Y');
}
if(emptyempty($month)){
    $month = date('m');
}
 
if(emptyempty($month)){
    $days = date('d');
}
 
$start_weekday = date('w',mktime(0,0,0,$month,1,$year));
//echo $start_weekday;
$days = date('t',mktime(0,0,0,$month,1,$year));
//echo $days;
$week = array('日','一','二','三','四','五','六');
$i = 0;
$k = 1;
$j = 0;
echo '';
echo '';
echo '';
for($i = 0;$i < 7;$i++){
    echo '';
}
echo '';
echo '';
for($j = 0;$j < $start_weekday;$j++){
    echo '';
}
while($k <= $days){
    if($k == $day){
        echo '';
    }else{
        echo '';
    }
    if(($j+1) % 7 == 0){
        echo '';
    }
    $j++;
    $k++;
}
while($j % 7 != 0){
    echo '';
    $j++;
}
echo '';
 
echo '';
echo "';
echo "';
echo '';
echo "';
echo "';
echo '';
echo '
'.$year.'年'.$month.'月'.'
'.$week[$i].'
'.$j.''.$k.''.$k.'
'.$j.'
".'<<'.'".'<'.'';
echo '
';
echo '';
echo '';
/*echo '月';*/
/*echo '';*/
echo '
';
echo '
".'>>'.'".'>'.'
';
 
function lastYear($year,$month){
 $year = $year-1;
 return "year=$year&month=$month";
}
function lastMonth($year,$month){
 if($month == 1){
$year = $year -1;
$month = 12;
}else{
$month--;
}
return "year=$year&month=$month";
}
function nextYear($year,$month){
$year = $year+1;
return "year=$year&month=$month";
}
function nextMonth($year,$month){
if($month == 12){
$year = $year +1;
$month = 1;
}else {
$month++;
}
return "year=$year&month=$month";
}

?>

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/924540.htmlTechArticleTwo php date control class examples, php date class examples This article describes two php date control classes. Share it with everyone for your reference. The specific analysis is as follows: Due to work needs, I found...
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