代码如下:

 <?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. Activity intent经常使用的 FLAG

    Intent.FLAG_ACTIVITY_NEW_TASK 默认的跳转类型,会重新创建一个新的Activity,不过与这种情况,比方说Task1中有A,B,C三个Activity,此时在C中启动D的话 ...

  2. Android 6.0 源代码编译实践

    http://www.judymax.com/archives/1087 Android 6.0 源代码编译实践 https://mirrors.tuna.tsinghua.edu.cn/help/A ...

  3. 実行時にMicrosoft.ACE.OLEDB.12.0プロバイダーはローカルコンピュータに登録されていませんが出てしまう

    環境 Windows8 64bit Visual Studio 2010 Access 2010 32bit 接続プロバイダは「Microsoft.ACE.OLEDB.12.0」 対応 Downloa ...

  4. MiniCrowler

    MiniCrawler Github Path : https://github.com/LixinZhang/miniCrowler Introduction: MiniCrawler is a s ...

  5. Ubuntu12.04 安装PyCharm

    1. 下载 选择Linux Tab,选择下载免费的Community Edition[1].当前版本是3.4 2. 安装PyCharm 按照官网给出的安装指导[2]进行安装. (1) Copy the ...

  6. 架构模式之REST架构

    直至今日,分布式系统(Distributed System)已经取得了大规模的应用,特别是Web的发展,已经给软件开发带来了翻天覆地的变化,这一点已经毋庸置疑了. 构建分布式系统常用的技术通常就是使用 ...

  7. 网友对twisted deferr的理解

    事實上Deferred的確就像是一連串的動作,用callback的形式被串在一起,我們用deferred或許可以這樣寫 d.addCallback(洗菜)d.addCallback(切菜)d.addC ...

  8. WinFrom 登录窗体 密码保存效果

    WinFrom 登录窗体 保存密码效果 开发CS程序的程序员都会遇到 今天突然想把这个功能加到我的项目中 之后总结下 不多说 上图   如果关闭程序 下次在登录的时候 用户名.密码会自动保留下来  一 ...

  9. ubuntu14.04服务版/etc/init.d/smbd restart无效的解决方法

    刚装的ubuntu14.04配置完smbd发现service或者/etc/init.d/smbd restart都不显示任何输出,也没起作用 echo $?输出1,查看脚本发现 if init_is_ ...

  10. 逆转序列的递归/尾递归(+destructuring assignment)实现(JavaScript + ES6)

    这里是用 JavaScript 做的逆转序列(数组/字符串)的递归/尾递归实现.另外还尝鲜用了一下 ES6 的destructuring assignment + spread operator 做了 ...