两个php日期控制类实例(2)

<?php
header("content-type:text/html;charset=utf-8");
?>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
 
<link href="https://www.jb51.net/statics/css/zhaoshang.css" type="text/css">
<div>
<?php
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 '<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>'.$j.'</td>';
}
while($k <= $days){
    if($k == $day){
        echo '<td><a href="?year='.$year.'&month='.$month.'&day='.$k.'"><span>'.$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>'.$j.'</td>';
    $j++;
}
echo '</tr>';
 
echo '<tr>';
echo "<td><a href=?".lastYear($year,$month).">".'<<'.'</a></td>';
echo "<td><a href=?".lastMonth($year,$month).">".'<'.'</a></td>';
echo '<td colspan = 3 >';
echo '<form name = "myform" method = "GET">';
echo '<select name = 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>';
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>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/bf80c67174d68e781011a7c0de69e187.html