代码如下:

 <?php
/**
*
* 我的日历
* date_default_timezone_set date mktime
* @param int $year
* @param int $month
* @param string $timezone
* @author fc_lamp
* @blog: http://www.cnblogs.com/roucheng/
*/
function myCalender($year = '', $month = '', $timezone = 'Asia/Shanghai')
{ date_default_timezone_set ( $timezone );
$year = abs ( intval ( $year ) );
$month = abs ( intval ( $month ) ); //是否是32位机
if (is32())
{
if ($year < 1970 or $year >= 2038)
{
$year = date ( 'Y' );
}
} else
{
if ($year <= 0)
{
$year = date ( 'Y' );
} } if ($month <= 0 or $month > 12)
{
$month = date ( 'm' );
} //上一年
$pretYear = $year - 1;
//上一月
$mpYear = $year;
$preMonth = $month - 1;
if ($preMonth <= 0)
{
$preMonth = 1;
$mpYear = $pretYear;
} //下一年
$nextYear = $year + 1;
//下一月
$mnYear = $year;
$nextMonth = $month + 1;
if ($nextMonth > 12)
{
$nextMonth = 1;
$mnYear = $nextYear;
} //日历头
$html = <<<HTML
<table width="500" border="1">
<tr align="center">
<td><a href="?y=$pretYear">上一年</a></td>
<td><a href="?y=$mpYear&m=$preMonth">上一月</a></td>
<td><a href="?">回到今天</a></td>
<td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td>
<td><a href="?y=$nextYear">下一年</a></td>
</tr>
<tr align="center">
<td colspan="5">{$year}年{$month}月</td>
</tr>
<tr>
<td colspan="5">
<table width="100%" border="1">
<tr align="center">
<td style="background-color:#DAF0DD;">星期一</td>
<td style="background-color:#DAF0DD;">星期二</td>
<td style="background-color:#DAF0DD;">星期三</td>
<td style="background-color:#DAF0DD;">星期四</td>
<td style="background-color:#DAF0DD;">星期五</td>
<td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td>
<td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td>
</tr>
HTML; $currentDay = date ( 'Y-m-j' ); //当月最后一天
$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) ); //循环输出天数
$day = 1;
$line = '';
while ( $day <= $lastday )
{
$cday = $year . '-' . $month . '-' . $day; //当前星期几
$nowWeek = date ( 'N', mktime ( 0, 0, 0, $month, $day, $year ) ); if ($day == 1)
{
$line = '<tr align="center">';
$line .= str_repeat ( '<td>&nbsp;</td>', $nowWeek - 1 );
} if ($cday == $currentDay)
{
$style = 'style="color:red;"';
} else
{
$style = '';
} $line .= "<td $style>$day</td>"; //一周结束
if ($nowWeek == 7)
{
$line .= '</tr>';
$html .= $line;
$line = '<tr align="center">';
} //全月结束
if ($day == $lastday)
{
if ($nowWeek != 7)
{
$line .= str_repeat ( '<td>&nbsp;</td>', 7 - $nowWeek );
}
$line .= '</tr>';
$html .= $line; break;
} $day ++;
} $html .= <<<HTML
</table>
</td>
</tr>
</table>
HTML;
return $html;
} /**
*
* 检测是否是32位机
* @author fc_lamp
* @blog: fc-lamp.blog.163.com
*/
function is32()
{
$is32 = False;
if (strtotime ( '2039-10-10' ) === False)
{
$is32 = True;
}
return $is32;
}

php Calender(日历)代码的更多相关文章

  1. php 日历代码

    日历的PHP接口代码: $user_id = $_SESSION['user_id']; $year = isset($_REQUEST['tty']) ? intval($_REQUEST['tty ...

  2. java 日历代码实现

    System.out.println("请输入日期(按照格式:2030-3-10):"); //在控制台输入 //String str="2016-9-26"; ...

  3. PyQt4 进度条和日历 代码

    # -*- coding: utf-8 -*- """ ------------------------------------------------- File Na ...

  4. java中日历代码的实现

    import java.util.Scanner; com.lv.calendarWatch//包名 /* * 需求:输入一个年份和月份 ,显示当前月日情况 ,星期数要对应准确 * 1.1900年1月 ...

  5. [AY技术分享]WPF AYUI的高大上日历代码

    看到这里,也谢谢大家关注了AYUI 这次讲的是AY最近没事开发的AyDatePicker,先看效果图 SelectMode=DateTime模式 SelectMode=OnlySelectDate模式 ...

  6. Android 一个日历控件的实现代码

    转载  2017-05-19   作者:Othershe   我要评论 本篇文章主要介绍了Android 一个日历控件的实现代码,小编觉得挺不错的,现在分享给大家,也给大家做个参考.一起跟随小编过来看 ...

  7. js编写当天简单日历

    之前一直很想用javascript写一个日历,但是因为完全没有好的思路, 所以迟迟没有尝试.最近在网上刚好看到用javascript编写的简单日历的例子,代码量虽然不大, 但是我觉得很好地阐述了js日 ...

  8. 用JS编写日历的简单思路

    提要:本文以写当前时间环境下当月的日历表为例,用最简单的方法实现JavaScript日历,旨在展示JS世界中实用为本.简单为上的解决问题的思路. Web页中的日历一般离不开表格,通常都使用表格装载指定 ...

  9. 推荐一款JavaScript日历控件:kimsoft-jscalendar

    一.什么是 kimsoft-jscalendar     一个简洁的avaScript日历控件,可在Java Web项目,.NET Web 项目中使用 二.kimsoft-jscalendar 有什么 ...

随机推荐

  1. Transaction recovery: lock conflict caught and ignored

    Transaction recovery: lock conflict caught and ignored环境:RAC 4节点.oracle 11.2.0.4.redhat 5.9 64bit 问题 ...

  2. C# 匿名委托、匿名方法、匿名对象、Lambda表达式

    一.匿名类型可通过使用 new 运算符和对象初始值创建匿名类型.示例:var v = new { Name = "Micro", Message = "Hello&quo ...

  3. LR6 碱性电池才能带动微软鼠标

    LR6 碱性电池才能带动微软鼠标   好前一段买个一个微软无线鼠标后来动弹不得,更换电池也不行,本来lp说为什么不扔掉,但因为实在做得很漂亮一直带在身边.改用雷柏的普通无线鼠标后也很是好用.不过要经常 ...

  4. SQL Server 2012 各版本功能比较

    有关不同版本的 SQL Server 2012 所支持的功能的详细信息. 功能名称 Enterprise 商业智能 Standard Web Express with Advanced Service ...

  5. [转]Linux下的lds链接脚本详解

    转载自:http://linux.chinaunix.net/techdoc/beginner/2009/08/12/1129972.shtml     一. 概论 每一个链接过程都由链接脚本(lin ...

  6. Hive Streaming 追加 ORC 文件

    1.概述 在存储业务数据的时候,随着业务的增长,Hive 表存储在 HDFS 的上的数据会随时间的增加而增加,而以 Text 文本格式存储在 HDFS 上,所消耗的容量资源巨大.那么,我们需要有一种方 ...

  7. Tips for thrift

    Introduction I have designed and developed game servers successfully with thrift (http://thrift.apac ...

  8. C primer plus 练习题 第三章

    5. #include <stdio.h> int main() { float you_sec; printf("请输入你的年龄:"); scanf("%f ...

  9. 删除数据库数据,自增id清理

    方法一:Delete Form 表名 方法二:TRUNCATE TABLE 在功能上与不带 WHERE 子句的 DELETE 语句相同:二者均删除表中的全部行.但 TRUNCATE TABLE 比 D ...

  10. MFC资源冲突解决方法

    AFX_MANAGE_STATE(AfxGetStaticModuleState())   先看一个例子: 1.创建一个动态链接到MFC DLL的规则DLL,其内部包含一个对话框资源.指定该对话框ID ...