亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

PHP實現的日歷功能示例

 更新時間:2018年09月01日 14:44:36   作者:Json______  
這篇文章主要介紹了PHP實現的日歷功能,涉及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

Unix時間戳(timestamp)轉換工具:
http://tools.jb51.net/code/unixtime

更多關于PHP相關內容感興趣的讀者可查看本站專題:《php日期與時間用法總結》、《PHP數組(Array)操作技巧大全》、《PHP基本語法入門教程》、《PHP運算與運算符用法總結》、《php面向對象程序設計入門教程》、《PHP網絡編程技巧總結》、《php字符串(string)用法總結》、《php+mysql數據庫操作入門教程》及《php常見數據庫操作技巧匯總

希望本文所述對大家PHP程序設計有所幫助。

相關文章

最新評論