兩個php日期控制類執行個體,php日期類執行個體_PHP教程

來源:互聯網
上載者:User

兩個php日期控制類執行個體,php日期類執行個體


本文執行個體講述了兩個php日期控制類。分享給大家供大家參考。具體分析如下:

由於工作需要我找了二個時間日期控制,這個不用js只要php實現的,因為要帶參考查詢操作,感興趣的朋友可以參考一下,我自己用的是第二個,所以第二個己作了修改.

執行個體一,代碼如下:
複製代碼 代碼如下:<?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();
?>
執行個體二,代碼如下:
複製代碼 代碼如下:<?php
header("content-type:text/html;charset=utf-8");
?>




<?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 '



































'; 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 '
".'>>'.'".'>'.'
';

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";
}

?>

希望本文所述對大家的php程式設計有所協助。

http://www.bkjia.com/PHPjc/924540.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/924540.htmlTechArticle兩個php日期控制類執行個體,php日期類執行個體 本文執行個體講述了兩個php日期控制類。分享給大家供大家參考。具體分析如下: 由於工作需要我找了...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.