由两个文件组成:

第一个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. Rhythmk 学习 Hibernate 01 - maven 创建Hibernate 项目之 增删改查入门

    1.环境: Maven :3.1.1 开发工具:Spring Tool Suite 数据库 : Mysql  5.6 2.项目文件结构 文件代码: 2.1 .pom.xml <project x ...

  2. halcon控制显示精度(精确到小数点后6位,精度足够了)

    实践应用 set_tposition (WindowHandle3,50, 50) write_string (WindowHandle3, '半径 D1=' +Ra[i]$'#f') set_tpo ...

  3. eclipse liquibase 插件

    http://marketplace.eclipse.org/category/free-tagging/liquibase http://marketplace.eclipse.org/market ...

  4. 横向文本框 index获取索引 和 eq 实现

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. 7.25 9figting!

    TEXT 87 Fund management基金管理   A Miller's tale 米勒传奇(陈继龙编译) Dec 7th 2006 From The Economist print edit ...

  6. Linux学习---Linux目录结构说明

    1./- 根 每一个文件和目录从根目录开始. 只有root用户具有该目录下的写权限.请注意,/root是root用户的主目录,这与/.不一样 2./bin中 - 用户二进制文件 包含二进制可执行文件. ...

  7. 虚拟机Mac系统中VMware_tools安装和vm共享文件夹的设置(转)

    原文来源: http://wenku.baidu.com/link?url=KRgfG40q2SEwZfde9xA7HVKjCsFBkMcf83tyellnzsHYZ_ErU1hWpVmTHYZem0 ...

  8. 79. Word Search (Array; DFS,Back-Track)

    Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from l ...

  9. Python 入门学习(贰)文件/文件夹正则表达式批量重命名工具

    基于 Udacity 的 Python 入门课程 Programming Foundations with Python 基于 Python 2.7 思路 Project 2 是一个去除文件名中所有数 ...

  10. 1-为什么java的main方法必须是静态的

    为什么java的main方法必须是静态的   今天看类型信息时发现一个问题,不能再main方法中打印this关键字的信息,这时想起了之前的知识,不能再静态方法中调用this.理由很简单,this表示“ ...