主頁(yè) > 知識(shí)庫(kù) > PHP實(shí)現(xiàn)的日歷功能示例

PHP實(shí)現(xiàn)的日歷功能示例

熱門標(biāo)簽:電子圍欄 阿里云 科大訊飛語(yǔ)音識(shí)別系統(tǒng) Linux服務(wù)器 服務(wù)器配置 銀行業(yè)務(wù) 團(tuán)購(gòu)網(wǎng)站 Mysql連接數(shù)設(shè)置

本文實(shí)例講述了PHP實(shí)現(xiàn)的日歷功能。分享給大家供大家參考,具體如下:

?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); //獲取當(dāng)前的月的一號(hào)
$year=date("Y",$noe); //當(dāng)前的年
$month=date("m",$noe); //當(dāng)前的月
$week=date("w",$noe); // 每個(gè)月的一號(hào)是星期幾
$days=date("t",$noe); //每個(gè)月的總天數(shù)
$day=date("d"); //獲取今天是幾號(hào)
$as=$year-1; //獲取上一年的年
$bs=$month-1; //獲取上個(gè)月
$bs=$month+1; // 獲取下個(gè)月
$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" >上個(gè)月/a>/th>
     th>?php echo $year."-".$month."-".$day ?>/th>
     th>a href="?b=?php echo $bs; ?>" rel="external nofollow" rel="external nofollow" >下個(gè)月>>/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>"; //獲取當(dāng)月一號(hào)前面的空格
    }
    for($k=1;$k=$days;$k++){
      if($k==$day){
        echo "th>".$k."/th>"; //輸出今天是幾號(hào)
      }else{
        echo "td>".$k."/td>"; //輸出當(dāng)月天數(shù)
      }
      if(($k+$week)%7==0){
        echo "tr>/tr>"; // 一周七天換行
      }
    }
    ?>
  /tr>
 /table>
/body>
/html>

運(yùn)行結(jié)果:

PS:這里再為大家推薦幾款時(shí)間及日期相關(guān)工具供大家參考:

在線日期/天數(shù)計(jì)算器:
http://tools.jb51.net/jisuanqi/date_jisuanqi

在線日期計(jì)算器/相差天數(shù)計(jì)算器:
http://tools.jb51.net/jisuanqi/datecalc

在線日期天數(shù)差計(jì)算器:
http://tools.jb51.net/jisuanqi/onlinedatejsq

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

更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《php日期與時(shí)間用法總結(jié)》、《PHP數(shù)組(Array)操作技巧大全》、《PHP基本語(yǔ)法入門教程》、《PHP運(yùn)算與運(yùn)算符用法總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》、《PHP網(wǎng)絡(luò)編程技巧總結(jié)》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫(kù)操作入門教程》及《php常見(jiàn)數(shù)據(jù)庫(kù)操作技巧匯總》

希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。

您可能感興趣的文章:
  • php+javascript的日歷控件
  • 用 php 編寫的日歷
  • php下實(shí)現(xiàn)農(nóng)歷日歷的代碼
  • 教大家制作簡(jiǎn)單的php日歷
  • php+mysql+jquery實(shí)現(xiàn)日歷簽到功能
  • PHP完整的日歷類(CLASS)
  • PHP輸出日歷表代碼實(shí)例
  • PHP實(shí)現(xiàn)的簡(jiǎn)單日歷類
  • 基于ThinkPHP實(shí)現(xiàn)的日歷功能實(shí)例詳解
  • php實(shí)現(xiàn)的日歷程序
  • 分享3個(gè)php獲取日歷的函數(shù)

標(biāo)簽:萍鄉(xiāng) 衢州 大理 棗莊 廣元 江蘇 衡水 蚌埠

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《PHP實(shí)現(xiàn)的日歷功能示例》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266