首页新萄京娱乐网址2492777 › 新萄京娱乐网址2492777php简单的日历程序代码

新萄京娱乐网址2492777php简单的日历程序代码

正文实例呈报了两个php日期调整类。分享给我们供我们参照他事他说加以考察。具体剖判如下:

<?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 ="<td colspan='2'><div align='center'><a
href=$PHP_SELF?year=".$lastyear."&month=".$lastmonth."&><<<</a></div></td>";
  $str.="<td colspan='3'><div
align='center'>".$this->year."--".$this->month."</div></td>";
  $str.="<td colspan='2'><div align='center'><a
href=$PHP_SELF?year=".$nextyear."&month=".$nextmonth."&>>>></a></div></td>";
  return $str;
 }
 
 
 function Show_Calendar()
 {
        echo "<table width='181' border=5><tr
class='tr.title'>".$this->title_link()."</tr><tr>";
        $weekarray=array("日","一","二","三","四","五","六");
       
        for($k=0;$k<=6;$k++)
        {
         echo "<td><div
align='center'>".$weekarray[$k]."</div></td>";
        }
        echo "</tr>";
       
        for($i=0;$i<=5;$i++)
        {
         echo "<tr>";
         for($j=1;$j<=7;$j++)
         {
    $math=( $j - $this->oneday_week() ) + 7 * $i;
   
          echo "<td><div align='center'>";
   
          if($math <= $this->endday() and $math>=1)
    {
         echo $math;
    }
   
         echo "</div></td>";
         }   
         echo "</tr>";    
        }
  echo "</table>";
         
 }
}

/*$calendar=new Calendar($_GET['year'],$_GET['month']);
//$calendar->month=$_GET['month'];
//$calendar->year=$_GET['year'];
$calendar->Show_Calendar();*/

//第二个

?>

通过date(卡塔尔函数能够比较轻易得到地点的数量

鉴于职业急需自个儿找了三个日子日期调节,这么些不要js只要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 ="

<?php
header("content-type:text/html;charset=utf-8");
?>
<meta http-equiv="content-type"
content="text/html;charset=utf-8">

<link
href="statics/css教程/zhaoshang.css"
rel="stylesheet" type="text/css">
<div class="rili">
<?php
if(!empty($_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(empty($year)){
    $year = date('Y');
}
if(empty($month)){
    $month = date('m');
}

if(empty($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 '<table >';
echo '<tr><td colspan = 7 style ="text-align:center;
width:250px; background:#d5e5f6; border-bottom:1px solid
#333366;">'.$year.'年'.$month.'月'.'</td></tr>';
echo '<tr>';
for($i = 0;$i < 7;$i++){
    echo '<td>'.$week[$i].'</td>';
}
echo '</tr>';
echo '<tr>';
for($j = 0;$j < $start_weekday;$j++){
    echo '<td style="color:#f1f8fc;">'.$j.'</td>';
}
while($k <= $days){
    if($k == $day){
        echo '<td style="color:red"><a
href="?year='.$year.'&month='.$month.'&day='.$k.'"><span
style="color:red">'.$k.'</span></a></td>';
    }else{
        echo '<td><a
href="?year='.$year.'&month='.$month.'&day='.$k.'">'.$k.'</a></td>';
    }
    if(($j+1) % 7 == 0){
        echo '</tr><tr>';
    }
    $j++;
    $k++;
}
while($j % 7 != 0){
    echo '<td style="color:#f1f8fc;">'.$j.'</td>';
    $j++;
}
echo '</tr>';

echo '<tr style="background:#d5e5f6;">';
echo "<td><a
href=?".lastYear($year,$month).">".'<<'.'</a></td>';
echo "<td><a
href=?".lastMonth($year,$month).">".'<'.'</a></td>';
echo '<td colspan = 3 style="width:105px;" >';
echo '<form name = "myform" method = "GET">';
echo '<select name = year 
class="year">';
for($start_year = 1970;$start_year<2039;$start_year++){
 $selected='';
 if( $year== $start_year ) { $selected='selected'; }
 echo '<option value ='. $start_year.'
'.$selected.'>'.$start_year.'</option>'." nt";
}
echo '</select>';
echo '<select name = month class="month">';
for($start_month = 1;$start_month<=12;$start_month++){
 $selected='';
 if( $month== $start_month ) { $selected='selected';}
 echo '<option value = '.$start_month.'
'.$selected.'>'.$start_month.'</option>'." nt";
}
echo '</select>';
/*echo '月';*/
/*echo '<input type = "submit" name = "search" value =
"查询">';*/
echo '</form>';
echo '</td>';
echo "<td><a
href=?".nextYear($year,$month).">".'>>'.'</a></td>';
echo "<td><a
href=?".nextMonth($year,$month).">".'>'.'</a></td>';
echo '</tr>';
echo '</table>';

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";
}

?>
</div>
 

<?php

<<<<>

$month = $_GET['m']?$_GET['m']:date(‘n’);
$year = $_GET['y']?$_GET['y']:date(‘Y’);

";
  $str.="

$start_week = date(‘w’,mktime(0,0,0,$month,1,$year));
$day_num = date(‘t’,mktime(0,0,0,$month,1,$year));
$end = false;
?>
<table>
<tr>
<td>星期日</td><td>星期一</td><td>星期二</td><td>星期三</td><td>星期四</td><td>星期五</td><td>星期六</td>
</tr>
<tr>
<?php
for($i = 0; $i<$start_week; $i++)
{
echo “<td></td>”;
}

".$this->year."--".$this->month."<>

$j=1;

";
  $str.="

while($j<=$day_num)
{
echo “<td>$j</td>”;
$week = ($start_week+$j-1)%7;

>>><>

if($week ==6){
echo “nt</tr>n”;
if($j != $day_num)
echo “t<tr>ntt”;
else $end = true;
}
$j++;
}
while($week%7 != 6)
{
echo “<td></td>”;
$week++;
}
if(!$end)
echo “n</tr>”;
?>

";
  return $str;
 }
 
 function Show_Calendar()
 {
        echo "

</table>

".$this->title_link()."

尖端一点类

";
        $weekarray=array("日","一","二","三","四","五","六");
        
        for($k=0;$k<=6;$k++)
        {
         echo "

 代码如下

".$weekarray[$k]."<>

<?php
class Calendar
{
    private $year;
    private $month;
    private $weeks  = array('日','一','二','三','四','五','六');
   
    function __construct($options = array()) {
        $this->year = date('Y');
        $this->month = date('m');
       
        $vars = get_class_vars(get_class($this));
        foreach ($options as $key=>$value) {
            if (array_key_exists($key, $vars)) {
                $this->$key = $value;
            }
        }
    }
   
    function display()
    {
        echo '<table class="calendar">';
        $this->showChangeDate();
        $this->showWeeks();
        $this->showDays($this->year,$this->month);
        echo '</table>';
    }
   
    private function showWeeks()
    {
        echo '<tr>';
        foreach($this->weeks as $title)
        {
            echo '<th>'.$title.'</th>';
        }
        echo '</tr>';
    }
   
    private function showDays($year, $month)
    {
        $firstDay = mktime(0, 0, 0, $month, 1, $year);
        $starDay = date('w', $firstDay);
        $days = date('t', $firstDay);

";
        }
        echo "

        echo '<tr>';
        for ($i=0; $i<$starDay; $i++) {
            echo '<td> </td>';
        }
       
        for ($j=1; $j<=$days; $j++) {
            $i++;
            if ($j == date('d')) {
                echo '<td class="today">'.$j.'</td>';
            } else {
                echo '<td>'.$j.'</td>';
            }
            if ($i % 7 == 0) {
                echo '</tr><tr>';
            }
        }
       
        echo '</tr>';
    }
   
    private function showChangeDate()
    {
       
        $url = basename($_SERVER['PHP_SELF']);
       
        echo '<tr>';
 echo '<td><a
href="?'.$this->preYearUrl($this->year,$this->month).'">'.'<<'.'</a></td>';
 echo '<td><a
href="?'.$this->preMonthUrl($this->year,$this->month).'">'.'<'.'</a></td>';
        echo '<td colspan="3"><form>';
       
        echo '<select name="year"
onchange="window.location=''.$url.'?year='+this.options[selectedIndex].value+'&month='.$this->month.''">';
        for($ye=1970; $ye<=2038; $ye++) {
            $selected = ($ye == $this->year) ? 'selected' : '';
            echo '<option '.$selected.'
value="'.$ye.'">'.$ye.'</option>';
        }
        echo '</select>';
        echo '<select name="month"
onchange="window.location=''.$url.'?year='.$this->year.'&month='+this.options[selectedIndex].value+''">';
       

";
        
        for($i=0;$i<=5;$i++)
        {
         echo "

       
        for($mo=1; $mo<=12; $mo++) {
            $selected = ($mo == $this->month) ? 'selected' : '';
            echo '<option '.$selected.'
value="'.$mo.'">'.$mo.'</option>';
        }
        echo '</select>';       
        echo '</form></td>';       
 echo '<td><a
href="?'.$this->nextMonthUrl($this->year,$this->month).'">'.'>'.'</a></td>';
 echo '<td><a
href="?'.$this->nextYearUrl($this->year,$this->month).'">'.'>>'.'</a></td>';       
        echo '</tr>';
    }
   
    private function preYearUrl($year,$month)
    {
        $year = ($this->year <= 1970) ? 1970 : $year - 1 ;
       
        return 'year='.$year.'&month='.$month;
    }
   
    private function nextYearUrl($year,$month)
    {
        $year = ($year >= 2038)? 2038 : $year + 1;
       
        return 'year='.$year.'&month='.$month;
    }
   
    private function preMonthUrl($year,$month)
    {
        if ($month == 1) {
            $month = 12;
            $year = ($year <= 1970) ? 1970 : $year - 1 ;
        } else {
            $month--;
        }       
       
        return 'year='.$year.'&month='.$month;
    }
   
    private function nextMonthUrl($year,$month)
    {
        if ($month == 12) {
            $month = 1;
            $year = ($year >= 2038) ? 2038 : $year + 1;
        }else{
            $month++;
        }
        return 'year='.$year.'&month='.$month;
    }
   
}

";
         for($j=1;$j<=7;$j++)
         {
     $math=( $j - $this->oneday_week() ) + 7 * $i;
    
          echo "

调用方法

";
    
          if($math <= $this->endday() and $math>=1)
     {
   echo $math;
     }
    
         echo "<>

 代码如下

";
         }    
         echo "

<?php
$params = array();
if (isset($_GET['year']) && isset($_GET['month'])) {
    $params = array(
        'year' => $_GET['year'],
        'month' => $_GET['month'],
    );
}
$params['url']  = 'demo.php';
require_once 'calendar.class.php';
?>

";     
        }
  echo "

<html>
    <head>
        <title>日历demo</title>
        <meta http-equiv="Content-Type" content="text/html"
charset="UTF-8" />
        <style
type="text/css">
            table.calendar {
                border: 1px solid #050;
            }
            .calendar th, .calendar td {
                width:30px;
                text-align:center;
            }           
            .calendar th {
                background-color:#050;
                color:#fff;
            }
            .today{
  color:#fff;
  background-color:#050;               
            }
        </style>
    </head>
    <body>
        <div style="align:center">
            <?php
                $cal = new Calendar($params);
                $cal->display();
            ?>   
        </div>
    </body>
</html>

";
 }
}
$calendar=new Calendar($_GET['year'],$_GET['month']);
$calendar->month=$_GET['month'];
$calendar->year=$_GET['year'];
$calendar->Show_Calendar();
?>
实例二,代码如下:
复制代码 代码如下:

转载本站文章请注明出处:新萄京娱乐网址2492777 http://www.cdhbjs.com/?p=5321

上一篇:

下一篇:

相关文章