存档:

index.php

 <html>
<head>
<title>日历</title>
<style>
table{border:1px solid #050;}
.fontb{color:white;background:blue;}
th{width:30px;}
td,th{height:30px;text-align:center;}
form{margin:0px;padding:0px;}
</style>
</head>
<body>
<?php
require "calendar.class.php";
echo new Calendar;
?>
</body>
</html>

calendar.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(0,0,0,$this->month,1,$this->year));
$this->days = date("t",mktime(0,0,0,$this->month,1,$this->year));
} function __toString(){
$out .='<table align="center">';
$out .=$this->chageDate();
$out .=$this->weeksList();
$out .=$this->daysList();
$out .='</table>';
return $out;
} private function weeksList(){
$week = array('日','一','二','三','四','五','六');
$out .= '<tr>';
for($i=0;$i<count($week);$i++){
$out .= '<th class="fontb">'.$week[$i].'</th>';
}
$out .= '</tr>';
return $out;
} private function daysList(){
$out .= '<tr>';
for($j=0;$j<$this->start_weekday;$j++){
$out .= '<td>&nbsp;</td>';
}
for($k=1;$k<=$this->days;$k++){
$j++;
if($k==date('d')){
$out .= '<td class="fontb">'.$k.'</td>';
}
else{
$out .= '<td>'.$k.'</td>';
}
if($j%7==0){
$out .= '</tr><tr>';
}
}
while($j%7!=0){
$out .= '<td>&nbsp;</td>';
$j++;
}
$out .= '</tr>';
return $out;
} private function prevYear($year,$month){
$year = $year-1;
if($year<1970){
$year=1970;
}
return "year=($year)&month=($month)";
} private function prevMonth($year,$month){
if($month==1){
$year=$year-1;
if($year<1970){
$year=1970;
}
$month=12;
}
else{
$month--;
}
return "year=($year)&month=($month)";
} private function nextYear($year,$month){
$year=$year+1;
if($year>2038){
$year=2038;
}
return "year=($year)&month=($month)";
} private function nextMonth($year,$month){
if($month==12){
$year++;
if($year>2038){
$year=2038;
}
$month=1;
}
else{
$month++;
}
return "year=($year)&month=($month)";
} private function chageDate($url="index.php"){
$out .= '<tr>';
$out .= '<td><a href="'.$url.'?'.$this->prevYear($this->year,$this->month).'">'.'<<'.'</a></td>';
$out .= '<td><a href="'.$url.'?'.$this->prevMonth($this->year,$this->month).'">'.'<'.'</a></td>';
$out .= '<td colspan="3">';
$out .= '<form>';
$out .= '<select name="year" onchange="window.location=\''.$url.'?year=\'+this.options[selectedIndex].value+\'&month='.$this->month.'\'">';
for($sy=1970;$sy<=2038;$sy++){
$selected=($sy==$this->year)?"selected":"";
$out .='<option '.$selected.' value="'.$sy.'">'.$sy.'</option>';
}
$out .= '</select>';
$out .= '<select name="month" onchange="window.location=\''.$url.'?year='.$this->year.'&month=\'+this.options[selectedIndex].value">';
for($sm=1;$sm<=12;$sm++){
$selected1=($sm==$this->month)?"selected":"";
$out .= '<option '.$selected1.' value="'.$sm.'">'.$sm.'</option>';
}
$out .= '</select>';
$out .= '</form>';
$out .= '</td>';
$out .= '<td><a href="'.$url.'?'.$this->nextYear($this->year,$this->month).'">'.'>>'.'</a></td>';
$out .= '<td><a href="'.$url.'?'.$this->nextMonth($this->year,$this->month).'">'.'>'.'</a></td>';
$out .= '</tr>';
return $out;
}
}
?>

结果如下:

最新文章

  1. 从零自学Hadoop(19):HBase介绍及安装
  2. WPA: 4-Way Handshake failed - pre-shared key may be incorrect
  3. BZOJ3569 : DZY Loves Chinese II
  4. java环境搭建系列:JDK从下载安装到简单使用
  5. LUA脚本调用C场景,使用C API访问脚本构造的表
  6. Android:Touch和Click的区别
  7. h264 流、帧结构
  8. http断点续传原理:http头 Range、Content-Range
  9. text bss data的区别
  10. bootstrap-导航总结
  11. bootstrap学习笔记之基础导航条 http://www.imooc.com/code/3111
  12. (译文)学习ES6非常棒的特性——Async / Await函数
  13. CentOS 7 使用yum安装出现错误
  14. Response ServletContext 中文乱码 Request 编码 请求行 共享数据 转发重定向
  15. Maven - 在Eclipse中创建Maven项目
  16. leetcode:Roman to Integer and Integer to Roman
  17. 刨根究底字符编码之—UTF-16编码方式
  18. [HAOI2018]染色(容斥+NTT)
  19. bzoj 2226 LCMSum 欧拉函数
  20. FocusBI:租房分析可视化(PowerBI网址体验)

热门文章

  1. SpringBoot实战(一)之构建RestFul风格
  2. 高斯消元求主元——模意义下的消元cf1155E
  3. 失败 - 模块“MonitorLoop”打开电源失败。
  4. Android App的签名打包(晋级篇)
  5. openstack neutron 简单理解
  6. ASP.NET Core 如何设置发布环境
  7. freemark生成静态网页乱码问题
  8. Linux下安装pip无法使用的情况
  9. zookeeper报错 JAVA_HOME is not set
  10. c#一些处理解决方案(组件,库)