由两个文件组成:

第一个test.php

<style>
table {
border:1px solid #;
} .fontb {
color:white;
background:blue;
} th {
width:30px;
} td,th {
height:30px;
text-align:center; }
form {
margin:0px;
padding:0px;
}
</style>
<?php
include "calendar.class.php"; $calendar=new Calendar; $calendar->out();

第二个日历类:calendar.class.php

<?php
class Calendar {
private $year; //当前的年
private $month; //当前的月
private $start_weekday; //当月的第一天对应的是周几
private $days; //当前月一共多少天 function __construct(){
$this->year=isset($_GET["year"]) ? $_GET["year"] : date("Y");
$this->month=isset($_GET["month"]) ? $_GET["month"] : date("m"); $this->start_weekday=date("w", mktime(, , , $this->month, , $this->year));
$this->days=date("t", mktime(, , , $this->month, , $this->year));
} function out(){
echo '<table align="center">';
$this->chageDate("test.php");
$this->weeksList();
$this->daysList();
echo '</table>';
} private function weeksList(){
$week=array('日','一','二','三','四','五','六'); echo '<tr>';
for($i=; $i<count($week); $i++)
echo '<th class="fontb">'.$week[$i].'</th>'; echo '</tr>';
} private function daysList(){
echo '<tr>';
//输出空格(当前一月第一天前面要空出来)
for($j=; $j<$this->start_weekday; $j++)
echo '<td>&nbsp;</td>'; for($k=; $k<=$this->days; $k++){
$j++;
if($k==date('d'))
echo '<td class="fontb">'.$k.'</td>';
else
echo '<td>'.$k.'</td>'; if($j%==)
echo '</tr><tr>'; } //后面几个空格
while($j%!==){
echo '<td>&nbsp;</td>';
$j++;
} echo '</tr>';
} private function prevYear($year, $month){
$year=$year-; if($year < )
$year = ; return "year={$year}&month={$month}";
} private function prevMonth($year, $month){
if($month == ) {
$year = $year -; if($year < )
$year = ; $month=;
}else{
$month--;
} return "year={$year}&month={$month}";
} private function nextYear($year, $month){
$year = $year + ; if($year > )
$year = ; return "year={$year}&month={$month}";
} private function nextMonth($year, $month){
if($month==){
$year++; if($year > )
$year=; $month=;
}else{
$month++;
} return "year={$year}&month={$month}";
} private function chageDate($url=""){
echo '<tr>';
echo '<td><a href="?'.$this->prevYear($this->year, $this->month).'">'.'<<'.'</a></td>';
echo '<td><a href="?'.$this->prevMonth($this->year, $this->month).'">'.'<'.'</a></td>';
echo '<td colspan="3">';
echo '<form>';
echo '<select name="year" onchange="window.location=\''.$url.'?year=\'+this.options[selectedIndex].value+\'&month='.$this->month.'\'">';
for($sy=; $sy <= ; $sy++){
$selected = ($sy==$this->year) ? "selected" : "";
echo '<option '.$selected.' value="'.$sy.'">'.$sy.'</option>';
}
echo '</select>';
echo '<select name="month" onchange="window.location=\''.$url.'?year='.$this->year.'&month=\'+this.options[selectedIndex].value">';
for($sm=; $sm<=; $sm++){
$selected1 = ($sm==$this->month) ? "selected" : "";
echo '<option '.$selected1.' value="'.$sm.'">'.$sm.'</option>';
}
echo '</select>';
echo '</form>';
echo '</td>'; echo '<td><a href="?'.$this->nextYear($this->year, $this->month).'">'.'>>'.'</a></td>';
echo '<td><a href="?'.$this->nextMonth($this->year, $this->month).'">'.'>'.'</a></td>';
echo '</tr>';
} }

效果:

PHP设计日历类一 (38)的更多相关文章

  1. java基础22 日期类、日历类、日期格式类

    package com.dhb.code; import java.text.ParseException; import java.text.SimpleDateFormat; import jav ...

  2. C++ 1//设计立方体类 //创建立方体的类 //设计属性和行为 //获取立方体的面积和体积 //分别利用(全局函数 和 成员函数)判断俩个立方体是否相等

    1 //设计立方体类 2 //创建立方体的类 3 //设计属性和行为 4 //获取立方体的面积和体积 5 //分别利用(全局函数 和 成员函数)判断俩个立方体是否相等 6 #include <i ...

  3. NSCalenda日历类

    1. //将数据库时间和当前时间相比,得出时间差. + (NSString *)dateDescriptionWithDate:(NSDate *)date{ // NSCalendar日历类,提供了 ...

  4. iOS 日历类(NSCalendar)

    对于时间的操作在开发中很常见,但有时候我们需要获取到一年后的时间,或者一周后的时间.靠通过秒数计算是不行的.那就牵扯到另外一个日历类(NSCalendar).下面先简单看一下 NSDate let d ...

  5. 第五十九届冠军(使用C++设计一个类不能被继承)

    称号:使用C++设计一个类不能被继承. 分析:这是Adobe 公司2007 的笔试题最新校园招聘. 应聘者的C++基本功底外,还能考察反应能力,是一道非常好的题目. 分析:C++中父类的构造函数会调用 ...

  6. NSCalendar 日历类

    NSCalendar 日历类 Cocoa中对日期和时间的处理 NSCalendar (一) (2008-11-12 21:54:10) NSCalendar用于处理时间相关问题.比如比较时间前后.计算 ...

  7. java学习笔记之日期日历类

    java学习笔记之日期日历 Date日期类概述: 表示特定的瞬间,精确到毫秒 Date类的构造方法: 1.空参数构造方法 Date date = new Date(); 获取到当前操作系统中的时间和日 ...

  8. 日历类和日期类转换 并发修改异常 泛型的好处 *各种排序 成员和局部变量 接口和抽象类 多态 new对象内存中的变化

    day07 ==和equals的区别? ==用于比较两个数值 或者地址值是否相同.  equals 用于比较两个对象的内容是否相同   String,StringBuffer.StringBuilde ...

  9. 可视化设计,类Excel的快速开发平台

    活字格Web应用生成器,是可视化设计,类Excel的快速开发平台,接下来给大家介绍如何体现这些特点. 一.可视化设计 网页系统的开发,包含UI设计+代码编写的工作,最终形成网页系统.这要求系统开发人员 ...

随机推荐

  1. Haartraining 训练方法(这个样例真有用,能行)

    目标检测方法最初由Paul Viola [Viola01]提出,并由Rainer Lienhart [Lienhart02]对这一方法进行了改善.该方法的基本步骤为: 首先,利用样本(大约几百幅样本图 ...

  2. Delphi7 [Fatal Error] ClassPas.pas(8): File not found: 'DesignIntf.dcu'

    Delphi7 [Fatal Error] ClassPas.pas(8): File not found: 'DesignIntf.dcu' Add path to Project>Optio ...

  3. 更换windows xp序列号

    ON ERROR RESUME NEXT Dim VOL_PROD_KEY if Wscript.arguments.count<1 then VOL_PROD_KEY=InputBox(&qu ...

  4. asp.net webapi 参数绑定总结

    首先必须得更正下自己一直以来对于get请求和post请求理解的一个误区:get请求只能通过url传参,post请求只能通过body传参. 其实上面的理解是错误的,翻阅了不少资料及具体实践,正确理解应该 ...

  5. mysql安装版卸载,解压版安装

    卸载:https://blog.csdn.net/cxy_summer/article/details/70142322 解压版安装:https://blog.csdn.net/recky_wiers ...

  6. blocking network call

    [blocking network call] 阻塞的网络调用: 1.gethostbyname(): does not return until it has succeeded or failed ...

  7. centos7虚拟机安装elasticsearch6.4.x-遇到的坑

    OS:Centos7x虚拟机 1H2Gjdk:1.8elasticsearch:5.6.0 1.下载“elasticsearch-5.6.0.tar.gz”解压到/usr/local/elastics ...

  8. uva10288 Coupons 【概率 分数】

    题目: 题意: 一共n种不同的礼券,每次得到每种礼券的概率相同.求期望多少次可以得到所有n种礼券.结果以带分数形式输出.1<= n <=33. 思路: 假设当前已经得到k种,获得新的一种的 ...

  9. Python_01-入门基础

    以后我会发表一系列python脚本的学习资料,python版本为2.x. 目录: 1 Python入门基础 1.1 学习资源 1.2 所有语言的入门程序---Hello World!  1.3 帮助函 ...

  10. 【bzoj1911】[Apio2010]特别行动队

    1911: [Apio2010]特别行动队 Time Limit: 4 Sec  Memory Limit: 64 MBSubmit: 4048  Solved: 1913[Submit][Statu ...