php Calender(日历)代码
代码如下:
<?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> </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> </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(日历)代码的更多相关文章
- php 日历代码
日历的PHP接口代码: $user_id = $_SESSION['user_id']; $year = isset($_REQUEST['tty']) ? intval($_REQUEST['tty ...
- java 日历代码实现
System.out.println("请输入日期(按照格式:2030-3-10):"); //在控制台输入 //String str="2016-9-26"; ...
- PyQt4 进度条和日历 代码
# -*- coding: utf-8 -*- """ ------------------------------------------------- File Na ...
- java中日历代码的实现
import java.util.Scanner; com.lv.calendarWatch//包名 /* * 需求:输入一个年份和月份 ,显示当前月日情况 ,星期数要对应准确 * 1.1900年1月 ...
- [AY技术分享]WPF AYUI的高大上日历代码
看到这里,也谢谢大家关注了AYUI 这次讲的是AY最近没事开发的AyDatePicker,先看效果图 SelectMode=DateTime模式 SelectMode=OnlySelectDate模式 ...
- Android 一个日历控件的实现代码
转载 2017-05-19 作者:Othershe 我要评论 本篇文章主要介绍了Android 一个日历控件的实现代码,小编觉得挺不错的,现在分享给大家,也给大家做个参考.一起跟随小编过来看 ...
- js编写当天简单日历
之前一直很想用javascript写一个日历,但是因为完全没有好的思路, 所以迟迟没有尝试.最近在网上刚好看到用javascript编写的简单日历的例子,代码量虽然不大, 但是我觉得很好地阐述了js日 ...
- 用JS编写日历的简单思路
提要:本文以写当前时间环境下当月的日历表为例,用最简单的方法实现JavaScript日历,旨在展示JS世界中实用为本.简单为上的解决问题的思路. Web页中的日历一般离不开表格,通常都使用表格装载指定 ...
- 推荐一款JavaScript日历控件:kimsoft-jscalendar
一.什么是 kimsoft-jscalendar 一个简洁的avaScript日历控件,可在Java Web项目,.NET Web 项目中使用 二.kimsoft-jscalendar 有什么 ...
随机推荐
- 定时从远程的数据库中取数据,然后把取出来的数据插入或更新本地的oracle数据库的表
最近项目中有一种需求: 大致需求是这样的 通过给定的 用户名和密码 要定时从远程的数据库中取数据,然后把取出来的数据插入或更新本地的oracle数据库的表 项目的结构式struts1 hibernat ...
- Metaweblog在Android上使用
同步发表于http://avenwu.net/2015/02/04/metaweblog metaweblog是一个博客接口协议,目前主流的博客平台均支持该协议,比如博客园,CSDN,WordPres ...
- jQuery File Upload跨域上传
最近在做一个一手粮互联网项目,方案为前后端分离,自己负责前端框架,采用了Requirejs+avalonjs+jquery三个框架完成. 前后端通过跨域实现接口调用,中间也发现了不少问题,尤其是在富文 ...
- 解读Gartner《2015年度新兴技术成熟度曲线报告》
详细见:http://www.360doc.com/content/16/0209/16/26186435_533443133.shtml 今年的报告评估了112个领域超过2000项新型技术的市场类型 ...
- LCLFramework框架之IOC
我们都知道,在采用面向对象方法设计的软件系统中,它的底层实现都是由N个对象组成的,所有的对象通过彼此的合作,最终实现系统的业务逻辑. 借助于"第三方"实现具有依赖关系的对象之间的解 ...
- BCB6 重装后的项目编译莫名问题
我很少用 bcb ,重装 bcb6 后原来的项目居然不能编译成功了,看了一下是控件的问题,但很多控件实际上并不关联的,而 bcb 坚持要你"拥有"当时的控件环境,折腾很久实在是没发 ...
- Difference between LET and LET* in Common LISP
Difference between LET and LET* in Common LISP LET Parallel binding which means the bindings com ...
- Reset Entity-Framework Migrations
You need to delete the state: Delete the migrations folder in your project Delete the __MigrationHis ...
- DataInputStream类和RandomAccessFile类的使用方法
// DataInputStream类实现了DataInput接口,要想从文件中读入二进制数据, // 你需要将DataInputStream与某个字节源相结合,例如FileInputStream / ...
- webClient请求JAVA超时解决方案
private class MyWebClient: WebClient { protected override WebRequest GetWebRequest(Uri uri) { WebReq ...