登录  /  注册
两个php日期控制类_PHP教程
php中文网
发布: 2016-07-20 11:10:08
原创
705人浏览过

由于工作需要我找了二个时间日期控制,这个不用js只要php实现的,因为要带参考查询所以操作了操作,有需要的朋友可以参考一下哦,我自己用的是第二个,所以第二个己作了修改。

class Calendar
{
var $month;
var $year;

function __construct($year,$month)
{
$this->year=$year;
$this->month=$month;
}

function endday()
{
$daydate=date("d",mktime(0,0,0,$this->month,35,$this->year));
$endday=35-$daydate;
return $endday;
}

function oneday_week()
{
$oneday_week=date("w",mktime(0,0,0,$this->month,1,$this->year));
return $oneday_week;
}

function title_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 ="

";
$str.="
".$this->year."--".$this->month."
";
$str.="";
return $str;
}


function Show_Calendar()
{
echo "".$this->title_link()."";
$weekarray=array("日","一","二","三","四","五","六");

for($k=0;$k<=6;$k++)
{
echo "";
}
echo "";

for($i=0;$i<=5;$i++)
{
echo "";
for($j=1;$j<=7;$j++)
{
$math=( $j - $this->oneday_week() ) + 7 * $i;

echo "";
}
echo "";
}
echo "
".$weekarray[$k]."
";

if($math <= $this->endday() and $math>=1)
{
echo $math;
}

echo "
";

}
}

/*$calendar=new Calendar($_GET['year'],$_GET['month']);
//$calendar->month=$_GET['month'];
//$calendar->year=$_GET['year'];
$calendar->Show_Calendar();*/


//第二个

?>

实例二

header("content-type:text/html;charset=utf-8");
?>



if(!empty($_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(empty($year)){
$year = date('Y');
}
if(empty($month)){
$month = date('m');
}

if(empty($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 '

';
echo '';
echo '';
for($i = 0;$i < 7;$i++){
echo '';
}
echo '';
echo '';
for($j = 0;$j < $start_weekday;$j++){
echo '';
}
while($k <= $days){
if($k == $day){
echo '';
}else{
echo '';
}
if(($j+1) % 7 == 0){
echo '';
}
$j++;
$k++;
}
while($j % 7 != 0){
echo '';
$j++;
}
echo '';

echo '

';
echo "';
echo "';
echo '';
echo "';
echo "';
echo '';
echo '
'.$year.'年'.$month.'月'.'
'.$week[$i].'
'.$j.''.$k.''.$k.'
'.$j.'
".'<<'.'".'<'.'';
echo '
';
echo '';
echo '';
/*echo '月';*/
/*echo '';*/
echo '
';
echo '
".'>>'.'".'>'.'
';

function lastYear($year,$month){
$year = $year-1;
return "year=$year&month=$month";
}
function lastMonth($year,$month){
if($month == 1){
$year = $year -1;
$month = 12;
}else{
$month--;
}
return "year=$year&month=$month";
}
function nextYear($year,$month){
$year = $year+1;
return "year=$year&month=$month";
}
function nextMonth($year,$month){
if($month == 12){
$year = $year +1;
$month = 1;
}else {
$month++;
}
return "year=$year&month=$month";
}

?>



www.bkjia.comtruehttp://www.bkjia.com/PHPjc/444741.htmlTechArticle由于工作需要我找了二个时间日期控制,这个不用js只要php实现的,因为要带参考查询所以操作了操作,有需要的朋友可以参考一下哦,我自...

来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门推荐
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 技术文章
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2023 //m.sbmmt.com/ All Rights Reserved | 苏州跃动光标网络科技有限公司 | 苏ICP备2020058653号-1

 | 本站CDN由 数掘科技 提供

登录PHP中文网,和优秀的人一起学习!
全站2000+教程免费学