PHP實現(xiàn)的日歷功能示例
本文實例講述了PHP實現(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); //獲取當前的月的一號
$year=date("Y",$noe); //當前的年
$month=date("m",$noe); //當前的月
$week=date("w",$noe); // 每個月的一號是星期幾
$days=date("t",$noe); //每個月的總天數(shù)
$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> </td>"; //獲取當月一號前面的空格
}
for($k=1;$k<=$days;$k++){
if($k==$day){
echo "<th>".$k."</th>"; //輸出今天是幾號
}else{
echo "<td>".$k."</td>"; //輸出當月天數(shù)
}
if(($k+$week)%7==0){
echo "<tr></tr>"; // 一周七天換行
}
}
?>
</tr>
</table>
</body>
</html>
運行結(jié)果:

PS:這里再為大家推薦幾款時間及日期相關工具供大家參考:
在線日期/天數(shù)計算器:
http://tools.jb51.net/jisuanqi/date_jisuanqi
在線日期計算器/相差天數(shù)計算器:
http://tools.jb51.net/jisuanqi/datecalc
在線日期天數(shù)差計算器:
http://tools.jb51.net/jisuanqi/onlinedatejsq
Unix時間戳(timestamp)轉(zhuǎn)換工具:
http://tools.jb51.net/code/unixtime
更多關于PHP相關內(nèi)容感興趣的讀者可查看本站專題:《php日期與時間用法總結(jié)》、《PHP數(shù)組(Array)操作技巧大全》、《PHP基本語法入門教程》、《PHP運算與運算符用法總結(jié)》、《php面向?qū)ο蟪绦蛟O計入門教程》、《PHP網(wǎng)絡編程技巧總結(jié)》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對大家PHP程序設計有所幫助。
相關文章
php json轉(zhuǎn)換成數(shù)組形式代碼分享
這篇文章主要介紹了php json轉(zhuǎn)換成數(shù)組形式代碼分享,需要的朋友可以參考下2014-11-11
如何解決CI框架的Disallowed Key Characters錯誤提示
本篇文章是對解決CodeIgniter框架應用中,出現(xiàn)Disallowed Key Characters錯誤提示的方法,進行了詳細的分析介紹,需要的朋友可以參考下2013-07-07
使用PHP連接多種數(shù)據(jù)庫的實現(xiàn)代碼(mysql,access,sqlserver,Oracle)
我們今天為大家介紹的PHP連接數(shù)據(jù)庫的方法包括在MYSQL數(shù)據(jù)庫、ACCESS數(shù)據(jù)庫、MS SQL數(shù)據(jù)庫和Oracle數(shù)據(jù)庫中實現(xiàn)2016-12-12

