两个php日期控制类实例,php日期类实例_PHP教程
程序员文章站
2022-05-19 11:11:24
...
两个php日期控制类实例,php日期类实例
本文实例讲述了两个php日期控制类。分享给大家供大家参考。具体分析如下:
由于工作需要我找了二个时间日期控制,这个不用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 {
$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.=" ";
$str.=" ";
return $str;
}
function Show_Calendar()
{
echo "
";
}
}
$calendar=new Calendar($_GET['year'],$_GET['month']);
$calendar->month=$_GET['month'];
$calendar->year=$_GET['year'];
$calendar->Show_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 {
$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 "
".$weekarray[$k]." | ";
"; if($math 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(!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 '';
';
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";
}
?>
?>
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 '
'.$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程序设计有所帮助。