PHP学院的中学生 2021-03-03 17:55:03 1012次浏览 0条回复 0 0 0
<?php
/*
 * Created by PhpStorm.
 * User: admin
 */
header("Content-Type:text/html;charset=utf-8");
date_default_timezone_set("PRC");
$a=@$_GET["a"];
$b=@$_GET["b"];
if($a){
  $a=$a;
}else{
  $a=date('y');
}
if($b){
  $b=$b;
}else{
  $b=date('m');
}
$noe=mktime(0,0,0,$b,1,$a); //获取当前的月的一号
$year=date("Y",$noe); //当前的年
$month=date("m",$noe); //当前的月
$week=date("w",$noe); // 每个月的一号是星期几
$days=date("t",$noe); //每个月的总天数
$day=date("d"); //获取今天是几号
$as=$year-1; //获取上一年的年
$bs=$month-1; //获取上个月
$bs=$month+1; // 获取下个月
$as=$year+1; //获取下一年
?>
<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>日历</title>
  <style>
    table{
      border: 1px solid #ddd;
    }
    
	.bottom tr td{
		width:50px;
		border:1px solid #ddd;
		text-align:center;
		padding:10px;
	}
	.top tr th{
		height:40px;
		width:94.1px;
		border:1px solid #ddd;
		
		padding:2px;  
    
	}
  </style>
</head>
<body>
<table class="top" cellpadding="0" cellspacing="0">
   <tr>
     <th><a href="?a=<?php echo $as; ?>" rel="external nofollow" rel="external nofollow" ><<上一年</a></th>
     <th><a href="?b=<?php echo $bs; ?>" rel="external nofollow" rel="external nofollow" ><<上个月</a></th>
     <th><?php echo $year."-".$month."-".$day ?></th>
     <th><a href="?b=<?php echo $bs; ?>" rel="external nofollow" rel="external nofollow" >下个月>></a></th>
     <th><a href="?a=<?php echo $as; ?>" rel="external nofollow" rel="external nofollow" >下一年>></a></th>
   </tr>
   </table>
 <table class="bottom" cellpadding="0" cellspacing="0">
   
   <tr style="margin-top:100px;">
     <td>周日</td>
     <td>周一</td>
     <td>周二</td>
     <td>周三</td>
     <td>周四</td>
     <td>周五</td>
     <td>周六</td>
   </tr>
  <tr>
    <?php
    for($i=0;$i<$week;$i++){
      echo "<td>&nbsp;</td>"; //获取当月一号前面的空格
    }
    for($k=1;$k<=$days;$k++){
      if($k==$day){
        echo "<th>".$k."</th>"; //输出今天是几号
      }else{
        echo "<td>".$k."</td>"; //输出当月天数
      }
      if(($k+$week)%7==0){
        echo "<tr></tr>"; // 一周七天换行
      }
    }
    ?>
  </tr>
 </table>
</body>
</html>
    没有找到数据。
您需要登录后才可以回复。登录 | 立即注册