




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
php簡單的日歷程序代碼PHP提供了date()函數(shù),該函數(shù)提供了豐富的日期處理功能?,F(xiàn)在需要獲得的數(shù)據(jù)有兩個,第一個是當(dāng)月的總天數(shù);第二個是該月的第一天所在星期中的第幾天,數(shù)字表示0(表示星期天)到6(表示星期六)。通過date()函數(shù)可以很容易獲得上面的數(shù)據(jù)
代碼如下復(fù)制代碼<?php$month=$_GET['m']?$_GET['m']:date(‘n’);
$year=$_GET['y']?$_GET['y']:date(‘Y’);$start_week=date(‘w’,mktime(0,0,0,$month,1,$year));
$day_num=date(‘t’,mktime(0,0,0,$month,1,$year));
$end=false;
?>
<table>
<tr>
<td>星期日</td><td>星期一</td><td>星期二</td><td>星期三</td><td>星期四</td><td>星期五</td><td>星期六</td>
</tr>
<tr>
<?php
for($i=0;$i<$start_week;$i++)
{
echo“<td></td>”;
}$j=1;while($j<=$day_num)
{
echo“<td>$j</td>”;
$week=($start_week+$j-1)%7;if($week==6){
echo“nt</tr>n”;
if($j!=$day_num)
echo“t<tr>ntt”;
else$end=true;
}
$j++;
}
while($week%7!=6)
{
echo“<td></td>”;
$week++;
}
if(!$end)
echo“n</tr>”;
?></table>高級一點類
代碼如下復(fù)制代碼<?php
classCalendar
{
private$year;
private$month;
private$weeks
=array('日','一','二','三','四','五','六');
function__construct($options=array()){
$this->year=date('Y');
$this->month=date('m');
$vars=get_class_vars(get_class($this));
foreach($optionsas$key=>$value){
if(array_key_exists($key,$vars)){
$this->$key=$value;
}
}
}
functiondisplay()
{
echo'<tableclass="calendar">';
$this->showChangeDate();
$this->showWeeks();
$this->showDays($this->year,$this->month);
echo'</table>';
}
privatefunctionshowWeeks()
{
echo'<tr>';
foreach($this->weeksas$title)
{
echo'<th>'.$title.'</th>';
}
echo'</tr>';
}
privatefunctionshowDays($year,$month)
{
$firstDay=mktime(0,0,0,$month,1,$year);
$starDay=date('w',$firstDay);
$days=date('t',$firstDay);
echo'<tr>';
for($i=0;$i<$starDay;$i++){
echo'<td> </td>';
}
for($j=1;$j<=$days;$j++){
$i++;
if($j==date('d')){
echo'<tdclass="today">'.$j.'</td>';
}else{
echo'<td>'.$j.'</td>';
}
if($i%7==0){
echo'</tr><tr>';
}
}
echo'</tr>';
}
privatefunctionshowChangeDate()
{
$url=basename($_SERVER['PHP_SELF']);
echo'<tr>';
echo'<td><ahref="?'.$this->preYearUrl($this->year,$this->month).'">'.'<<'.'</a></td>';
echo'<td><ahref="?'.$this->preMonthUrl($this->year,$this->month).'">'.'<'.'</a></td>';
echo'<tdn="3"><form>';
echo'<selectname="year"onchange="window.location=''.$url.'?year='+this.options[selectedIndex].value+'&month='.$this->month.''">';
for($ye=1970;$ye<=2038;$ye++){
$selected=($ye==$this->year)?'selected':'';
echo'<option'.$selected.'value="'.$ye.'">'.$ye.'</option>';
}
echo'</select>';
echo'<selectname="month"onchange="window.location=''.$url.'?year='.$this->year.'&month='+this.options[selectedIndex].value+''">';
for($mo=1;$mo<=12;$mo++){
$selected=($mo==$this->month)?'selected':'';
echo'<option'.$selected.'value="'.$mo.'">'.$mo.'</option>';
}
echo'</select>';
echo'</form></td>';
echo'<td><ahref="?'.$this->nextMonthUrl($this->year,$this->month).'">'.'>'.'</a></td>';
echo'<td><ahref="?'.$this->nextYearUrl($this->year,$this->month).'">'.'>>'.'</a></td>';
echo'</tr>';
}
privatefunctionpreYearUrl($year,$month)
{
$year=($this->year<=1970)?1970:$year-1;
return'year='.$year.'&month='.$month;
}
privatefunctionnextYearUrl($year,$month)
{
$year=($year>=2038)?2038:$year+1;
return'year='.$year.'&month='.$month;
}
privatefunctionpreMonthUrl($year,$month)
{
if($month==1){
$month=12;
$year=($year<=1970)?1970:$year-1;
}else{
$month--;
}
return'year='.$year.'&month='.$month;
}
privatefunctionnextMonthUrl($year,$month)
{
if($month==12){
$month=1;
$year=($year>=2038)?2038:$year+1;
}else{
$month++;
}
return'year='.$year.'&month='.$month;
}
}調(diào)用方法
代碼如下復(fù)制代碼<?php
$params=array();
if(isset($_GET['year'])&&isset($_GET['month'])){
$params=array(
'year'=>$_GET['year'],
'month'=>$_GET['month'],
);
}
$params['url']
='demo.php';
require_once'calendar.class.php';
?><html>
<head>
<title>日歷demo</title>
<metahttp-equiv="Content-Type"content="text/html"charset="UTF-8"/>
<styletype="text/css">
table.calendar{
border:1pxsolid#050;
}
.calendarth,.calendartd{
width:30px;
text-align:center;
}
.calendarth{
background-color:#050;
color:#fff;
}
.today{
color:#fff;
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 巨鹿縣足球組織活動方案
- 巾幗文明活動方案
- 小學(xué)紅領(lǐng)巾活動方案
- 尬舞大賽活動活動方案
- 工匠精神現(xiàn)場活動方案
- 師徒結(jié)對活動方案
- 崗位講述比賽活動方案
- 幫扶暖民心活動方案
- 幫扶消費活動方案
- 小班個別化活動活動方案
- 2024版消防設(shè)計質(zhì)量問題案例分析手冊建筑機電專業(yè)
- 《性病防治知識講座》課件
- YY/T 1944-2024醫(yī)用X射線高壓發(fā)生器專用技術(shù)條件
- 第10講-動能與動能定理-高一物理同步講義-原卷版
- 國開學(xué)習(xí)網(wǎng)《數(shù)據(jù)庫運維》形考任務(wù)1-3答案
- 2023年中國醫(yī)學(xué)科學(xué)院基礎(chǔ)醫(yī)學(xué)研究所高等學(xué)校招聘筆試真題
- 華南理工大學(xué)《論文寫作與學(xué)術(shù)規(guī)范》2021-2022學(xué)年第一學(xué)期期末試卷
- 2025年中考數(shù)學(xué)熱點題型歸納與變式演練(全國)專題09 幾何最值問題(原卷版)
- 安全、質(zhì)量、環(huán)境管理制度
- 六年級20道說理題
- 兩個女兒斷絕關(guān)系協(xié)議書范文
評論
0/150
提交評論