




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rè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)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- Module7 Unit1 He spent about twenty-one hours in space(教學(xué)設(shè)計)-2023-2024學(xué)年外研版(三起)英語六年級下冊
- 華北理工大學(xué)冀唐學(xué)院《研究型建筑設(shè)計》2023-2024學(xué)年第二學(xué)期期末試卷
- 山西國際商務(wù)職業(yè)學(xué)院《計算機(jī)組成原理理論》2023-2024學(xué)年第二學(xué)期期末試卷
- 哈爾濱鐵道職業(yè)技術(shù)學(xué)院《班級活動的組織》2023-2024學(xué)年第二學(xué)期期末試卷
- 遼寧民族師范高等??茖W(xué)校《機(jī)電系統(tǒng)設(shè)計與控制》2023-2024學(xué)年第二學(xué)期期末試卷
- 廣州東華職業(yè)學(xué)院《海洋生物技術(shù)綜合實驗》2023-2024學(xué)年第二學(xué)期期末試卷
- 南昌大學(xué)科學(xué)技術(shù)學(xué)院《新編大學(xué)生安全教育》2023-2024學(xué)年第二學(xué)期期末試卷
- 河北科技師范學(xué)院《西方財務(wù)會計雙語》2023-2024學(xué)年第二學(xué)期期末試卷
- 共青科技職業(yè)學(xué)院《學(xué)前兒童保育學(xué)》2023-2024學(xué)年第二學(xué)期期末試卷
- 陜西理工大學(xué)《數(shù)字信號處理》2023-2024學(xué)年第二學(xué)期期末試卷
- 社區(qū)意識形態(tài)工作2025年度工作計劃
- 2025年山東省濟(jì)南廣播電視臺招聘30人歷年管理單位筆試遴選500模擬題附帶答案詳解
- DG-TJ 08-2048-2024 民用建筑電氣防火設(shè)計標(biāo)準(zhǔn)
- 2025年中智集團(tuán)招聘筆試參考題庫含答案解析
- 黑龍江省哈爾濱市南崗區(qū)2024-2025學(xué)年九年級上學(xué)期期末考試英語試題(含答案)
- 殘疾人就業(yè)培訓(xùn)
- Photoshop+2024學(xué)習(xí)手冊:第1課認(rèn)識與操作基礎(chǔ)
- 《不同血流限制訓(xùn)練方案對膝關(guān)節(jié)損傷運動員下肢功能的影響》
- 藥品經(jīng)營企業(yè)(批發(fā)和零售)面臨的風(fēng)險點和應(yīng)對措施
- 北師大版(2024新版)七年級上冊數(shù)學(xué)期末模擬測試卷(含答案)
- 無人機(jī)組裝與調(diào)試 課件 項目1任務(wù)1 多旋翼無人機(jī)飛行平臺組裝調(diào)試
評論
0/150
提交評論