国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > PHP > 正文

兩個php日期控制類實例

2020-03-22 20:24:47
字體:
來源:轉載
供稿:網友
本文實例講述了兩個php日期控制類。分享給大家供大家參考。具體分析如下:由于工作需要我找了二個時間日期控制,這個不用js只要php實現的,因為要帶參考查詢操作,感興趣的朋友可以參考一下,我自己用的是第二個,所以第二個己作了修改.實例一,代碼如下:
復制代碼 代碼如下: php
html' target='_blank'>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 =" td colspan='2' div align='center' a href=$PHP_SELF year=".$lastyear."&month=".$lastmonth." /a /div /td
$str.=" td colspan='3' div align='center' ".$this- year."--".$this- month." /div /td
$str.=" td colspan='2' div align='center' a href=$PHP_SELF year=".$nextyear."&month=".$nextmonth." /a /div /td
return $str;
}

function Show_Calendar()
{
echo " table width='181' border=5 tr ".$this- title_link()." /tr tr
$weekarray=array("日","一","二","三","四","五","六");

for($k=0;$k $k++)
{
echo " td div align='center' ".$weekarray[$k]." /div /td
}
echo " /tr

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

echo " td div align='center'

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

echo " /div /td
}
echo " /tr
}
echo " /table
}
}
$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");

meta http-equiv="content-type" content="text/html;charset=utf-8"

link href="statics/css/zhaoshang.css" rel="stylesheet" type="text/css"
div
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 td colspan = 7 style ="text-align:center; width:250px; background:#d5e5f6; border-bottom:1px solid #333366;" '.$year.'年'.$month.'月'.' /td /tr
echo ' tr
for($i = 0;$i $i++){
echo ' td '.$week[$i].' /td
}
echo ' /tr
echo ' tr
for($j = 0;$j $start_weekday;$j++){
echo ' td '.$j.' /td
}
while($k = $days){
if($k == $day){
echo ' td a href=" year='.$year.'&month='.$month.'&day='.$k.'" span '.$k.' /span /a /td
}else{
echo ' td a href=" year='.$year.'&month='.$month.'&day='.$k.'" '.$k.' /a /td
}
if(($j+1) % 7 == 0){
echo ' /tr tr
}
$j++;
$k++;
}
while($j % 7 != 0){
echo ' td '.$j.' /td
$j++;
}
echo ' /tr

echo ' tr
echo " td a href= ".lastYear($year,$month)." ".' '.' /a /td
echo " td a href= ".lastMonth($year,$month)." ".' '.' /a /td
echo ' td colspan = 3
echo ' form name = "myform" method = "GET"
echo ' select name = year
for($start_year = 1970;$start_year 2039;$start_year++){
$selected='';
if( $year== $start_year ) { $selected='selected'; }
echo ' option value ='. $start_year.' '.$selected.' '.$start_year.' /option '." nt";
}
echo ' /select
echo ' select name = month
for($start_month = 1;$start_month $start_month++){
$selected='';
if( $month== $start_month ) { $selected='selected';}
echo ' option value = '.$start_month.' '.$selected.' '.$start_month.' /option '." nt";
}
echo ' /select
/*echo '月';*/
/*echo ' input type = "submit" name = "search" value = "查詢" */
echo ' /form
echo ' /td
echo " td a href= ".nextYear($year,$month)." ".' '.' /a /td
echo " td a href= ".nextMonth($year,$month)." ".' '.' /a /td
echo ' /tr
echo ' /table

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


/div 希望本文所述對大家的php程序設計有所幫助。PHP教程

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 三原县| 云安县| 兴隆县| 新丰县| 岫岩| 运城市| 香港 | 麻城市| 泰兴市| 宁晋县| 昭觉县| 林芝县| 九龙城区| 胶州市| 清丰县| 汉中市| 辽中县| 安庆市| 敦化市| 株洲市| 冷水江市| 舞阳县| 晋中市| 陇西县| 紫金县| 安国市| 桐城市| 资兴市| 恭城| 依安县| 井陉县| 茶陵县| 浦城县| 长泰县| 锦屏县| 岳阳县| 安西县| 南岸区| 油尖旺区| 大安市| 荥阳市|