两个php日期控制类实例
2023-06-13 09:15:32 时间
本文实例讲述了两个php日期控制类。分享给大家供大家参考。具体分析如下:
由于工作需要我找了二个时间日期控制,这个不用js只要php实现的,因为要带参考查询操作,感兴趣的朋友可以参考一下,我自己用的是第二个,所以第二个己作了修改.
实例一,代码如下:
classCalendar
{
var$month;
var$year;
function__construct($year,$month)
{
$this->year=$year;
$this->month=$month;
}
functionendday()
{
$daydate=date("d",mktime(0,0,0,$this->month,35,$this->year));
$endday=35-$daydate;
return$endday;
}
functiononeday_week()
{
$oneday_week=date("w",mktime(0,0,0,$this->month,1,$this->year));
return$oneday_week;
}
functiontitle_link()
{
if(!isset($this->month)&&!isset($this->year))
{
$this->year =date("Y");
$this->month=date("m");
}
$lastmonth=$this->month-1;
$nextmonth=$this->month+1;
$lastyear=$this->year;
$nextyear=$this->year;
if($this->month<=1)
{
$lastmonth=12;
$nextmonth=$this->month+1;
$lastyear=$this->year-1;
$nextyear=$this->year;
}
elseif($this->month>=12)
{
$lastmonth=$this->month-1;
$nextmonth=1;
$lastyear=$this->year;
$nextyear=$this->year+1;
}
$str="<tdcolspan="2"><divalign="center"><ahref=$PHP_SELF?year=".$lastyear."&month=".$lastmonth."&><<<</a></div></td>";
$str.="<tdcolspan="3"><divalign="center">".$this->year."--".$this->month."</div></td>";
$str.="<tdcolspan="2"><divalign="center"><ahref=$PHP_SELF?year=".$nextyear."&month=".$nextmonth."&>>>></a></div></td>";
return$str;
}
functionShow_Calendar()
{
echo"<tablewidth="181"border=5><trclass="tr.title">".$this->title_link()."</tr><tr>";
$weekarray=array("日","一","二","三","四","五","六");
for($k=0;$k<=6;$k++)
{
echo"<td><divalign="center">".$weekarray[$k]."</div></td>";
}
echo"</tr>";
for($i=0;$i<=5;$i++)
{
echo"<tr>";
for($j=1;$j<=7;$j++)
{
$math=($j-$this->oneday_week())+7*$i;
echo"<td><divalign="center">";
if($math<=$this->endday()and$math>=1)
{
echo$math;
}
echo"</div></td>";
}
echo"</tr>";
}
echo"</table>";
}
}
$calendar=newCalendar($_GET["year"],$_GET["month"]);
$calendar->month=$_GET["month"];
$calendar->year=$_GET["year"];
$calendar->Show_Calendar();
?>
实例二,代码如下:
header("content-type:text/html;charset=utf-8");
?>
<metahttp-equiv="content-type"content="text/html;charset=utf-8">
<linkhref="statics/css/zhaoshang.css"rel="stylesheet"type="text/css">
<divclass="rili">
<?php
if(!emptyempty($_GET)){
$year=isset($_GET["year"])?$_GET["year"]:date("y");
$month=isset($_GET["month"])?$_GET["month"]:date("m");
$day=isset($_GET["day"])?$_GET["day"]:date("d");
}
if(emptyempty($year)){
$year=date("Y");
}
if(emptyempty($month)){
$month=date("m");
}
if(emptyempty($month)){
$days=date("d");
}
$start_weekday=date("w",mktime(0,0,0,$month,1,$year));
//echo$start_weekday;
$days=date("t",mktime(0,0,0,$month,1,$year));
//echo$days;
$week=array("日","一","二","三","四","五","六");
$i=0;
$k=1;
$j=0;
echo"<table>";
echo"<tr><tdcolspan=7style="text-align:center;width:250px;background:#d5e5f6;border-bottom:1pxsolid#333366;">".$year."年".$month."月"."</td></tr>";
echo"<tr>";
for($i=0;$i<7;$i++){
echo"<td>".$week[$i]."</td>";
}
echo"</tr>";
echo"<tr>";
for($j=0;$j<$start_weekday;$j++){
echo"<tdstyle="color:#f1f8fc;">".$j."</td>";
}
while($k<=$days){
if($k==$day){
echo"<tdstyle="color:red"><ahref="?year=".$year."&month=".$month."&day=".$k.""><spanstyle="color:red">".$k."</span></a></td>";
}else{
echo"<td><ahref="?year=".$year."&month=".$month."&day=".$k."">".$k."</a></td>";
}
if(($j+1)%7==0){
echo"</tr><tr>";
}
$j++;
$k++;
}
while($j%7!=0){
echo"<tdstyle="color:#f1f8fc;">".$j."</td>";
$j++;
}
echo"</tr>";
echo"<trstyle="background:#d5e5f6;">";
echo"<td><ahref=?".lastYear($year,$month).">"."<<"."</a></td>";
echo"<td><ahref=?".lastMonth($year,$month).">"."<"."</a></td>";
echo"<tdcolspan=3style="width:105px;">";
echo"<formname="myform"method="GET">";
echo"<selectname=year class="year">";
for($start_year=1970;$start_year<2039;$start_year++){
$selected="";
if($year==$start_year){$selected="selected";}
echo"<optionvalue=".$start_year."".$selected.">".$start_year."</option>"."nt";
}
echo"</select>";
echo"<selectname=monthclass="month">";
for($start_month=1;$start_month<=12;$start_month++){
$selected="";
if($month==$start_month){$selected="selected";}
echo"<optionvalue=".$start_month."".$selected.">".$start_month."</option>"."nt";
}
echo"</select>";
/*echo"月";*/
/*echo"<inputtype="submit"name="search"value="查询">";*/
echo"</form>";
echo"</td>";
echo"<td><ahref=?".nextYear($year,$month).">".">>"."</a></td>";
echo"<td><ahref=?".nextMonth($year,$month).">".">"."</a></td>";
echo"</tr>";
echo"</table>";
functionlastYear($year,$month){
$year=$year-1;
return"year=$year&month=$month";
}
functionlastMonth($year,$month){
if($month==1){
$year=$year-1;
$month=12;
}else{
$month--;
}
return"year=$year&month=$month";
}
functionnextYear($year,$month){
$year=$year+1;
return"year=$year&month=$month";
}
functionnextMonth($year,$month){
if($month==12){
$year=$year+1;
$month=1;
}else{
$month++;
}
return"year=$year&month=$month";
}
?>
</div>
希望本文所述对大家的php程序设计有所帮助。
相关文章
- phpspreadsheet使用实例_php获取html中文本框内容
- redis锁机制介绍与实例
- ASP.NET操作MySQL数据库技术实例(aspx操作mysql)
- PHP扩展开发:实现Redis读写数据(php扩展redis)
- Oracle应用在企业中的实践研究(oracle应用实例)
- PHP如何使用Redis连接: 代码实例(php连接redis代码)
- 使用PHP操作Redis实例:简单高效的数据存储方案(php操作redis实例)
- 分布式数据库实现Redis单实例分布式数据库管理(redis单实例)
- 使用PHP实现Redis快速构建应用(redis实例php)
- 使用PHP实现Redis分布式缓存(php实例化redis)
- PHP连接MySQL数据库失败的解决方案(php连接mysql失败)
- 防止MySQL注入攻击,PHP静态解决方案(mysql防注入 php)
- PHP连接MSSQL数据库遇到问题:无法连接的解决方案(php 无法 mssql)
- PHP与MySQL:兼容性更好、更强大的灵活性(php与mysql 优点)
- 分析解析Redis缓存穿透 一个实例分析(redis 缓存穿透例子)
- PHP数据流应用的一个简单实例
- PHP学习笔记IIS7下安装配置php环境
- PHP数据库链接类(PDO+Access)实例分享
- python算法学习之计数排序实例
- JavaScript异步回调的Promise模式封装实例
- php的ZipArchive类用法实例
- asp.net实现批量删除实例
- 一个JavaScript用逗号分割字符串实例