PHP 에서 실 현 된 달력 기능 예시

4018 단어 PHP일력
이 글 의 실례 는 PHP 가 실현 하 는 달력 기능 을 다 루 었 다.여러분 께 참고 하도록 공유 하 겠 습 니 다.구체 적 으로 는 다음 과 같 습 니 다.

<?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 #050;
    }
    table th{
      background:#000;
      color:#fff;
      border: 2px solid #050;
    }
  </style>
</head>
<body>
 <table 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>
   <tr>
     <th>   </th>
     <th>   </th>
     <th>   </th>
     <th>   </th>
     <th>   </th>
     <th>   </th>
     <th>   </th>
   </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>

실행 결과:

PS:여기 서 몇 가지 시간 과 날짜 관련 도 구 를 추천 합 니 다.참고 하 시기 바 랍 니 다.
온라인 날짜/일수 계산기:
http://tools.jb51.net/jisuanqi/date_jisuanqi
온라인 날짜 계산기/차이 일수 계산기:
http://tools.jb51.net/jisuanqi/datecalc
온라인 날짜 일수 차 계산기:
http://tools.jb51.net/jisuanqi/onlinedatejsq
유 닉 스 타임 스탬프(timestamp)변환 도구:
http://tools.jb51.net/code/unixtime
더 많은 PHP 관련 내용 에 관심 이 있 는 독자 들 은 본 사이트 의 주 제 를 볼 수 있다.
본 논문 에서 말 한 것 이 여러분 의 PHP 프로 그래 밍 에 도움 이 되 기 를 바 랍 니 다.

좋은 웹페이지 즐겨찾기