php-万年历

<?php
    date_default_timezone_set("Asia/Shanghai");
    //时区
    $year=$_GET['y']?$_GET['y']:date("Y");
    //年份
    $month=$_GET['m']?$_GET['m']:date("n");
    //月份
    $days=date("t",strtotime("{$year}-{$month}"));
    //这个月有几天
    $week=date("w",strtotime("{$year}-{$month}"));
    //这个月一号是周几

    //

    //echo $y."年<br>";
    
    //echo $m."月<br>";
    
    //echo $days."日<br>";
    
    //echo "星期".$week."<br>";
    
    echo "<center>";
    //内容居中
    
    echo "<h2>{$year}年{$month}月</2>";
    //表头
    
    
    echo "<table width='700px' border='1px'>";    //表格
    echo "<tr>";
    echo "<th>日</th>";
    echo "<th>一</th>";
    echo "<th>二</th>";
    echo "<th>三</th>";
    echo "<th>四</th>";
    echo "<th>五</th>";
    echo "<th>六</th>";
    
    echo "</tr>";
    for($i=1-$week;$i<=$days;){
        echo "<tr>";
        for($j=0;$j<7;$j++){
            if($i>$days || $i<1){
                echo "<td>&nbsp;</td>";
            }

            else{
                echo "<td>{$i}</td>";
            }

            $i++;
        }
        echo "</tr>";
        
    }    
    
    echo "</table>";
    
    
    
    //上一月
        if($month==1){
            $prevyear=$year-1;
            $prevmonth=12;
        }
        else{
            $prevyear=$year;
            $prevmonth=$month-1;
        }
    

    //下一月
        if($month==12){
            $nextyear=$year+1;
            $nextmonth=1;
        }
        else{
            $nextyear=$year;
            $nextmonth=$month+1;
        }    
    echo "<h2><a href='Calendar.php?y={$prevyear}&m={$prevmonth}'>上一月</a>|<a href='Calendar.php?y={$nextyear}&m={$nextmonth}'>下一月</a></h2>";
    
    

    echo "</center>";
?>

 

posted on 2017-03-17 21:45  加号与剑豪  阅读(134)  评论(0编辑  收藏  举报

导航