Two PHP date control class instances, PHP date class instances
The examples in this article describe two PHP date control classes. Share to everyone for your reference. The specific analysis is as follows:
Because the work needs me to find two time date control, this does not need JS as long as PHP implementation, because to take the reference query operation, interested friends can refer to, I use the second one, so the second has been modified.
Example one, the code is as follows:
Copy CodeThe code is as follows: <?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 ("Day", "one", "two", "three", "four", "five", "six"); for ($k =0; $k <=6; $k + +) {echo "
". $weekarray [$k]." | "; } echo "
"; for ($i =0; $i <=5; $i + +) {echo "
"; for ($j =1; $j <=7; $j + +) {$math = ($j-$this->oneday_week ()) + 7 * $i; echo "
";
if ($math <= $this->endday () and $math >=1) { Echo $math; }
echo " | "; } echo "
"; } echo "
";
}
}
$calendar =new Calendar ($_get[' year '],$_get[' month ');
$calendar->month=$_get[' month ';
$calendar->year=$_get[' year ';
$calendar->show_calendar ();
?>
Example two, the code is as follows:
Copy CodeThe code is as follows: <?php
Header ("Content-type:text/html;charset=utf-8");
?>
<?php
if (!emptyempty ($_get)) {
$year = isset ($_get[' year ")? $_get[' year ':d ate (' Y ');
$month = isset ($_get[' month ')? $_get[' Month ':d ate (' m ');
$day = isset ($_get[' Day ")? $_get[' Day ':d ate (' 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 (' Day ', ' one ', ' two ', ' three ', ' four ', ' V ', ' VI ');
$i = 0;
$k = 1;
$j = 0;
Echo '
';Echo '
$year. ' Year ' $month. ' Month '. ' |
'; Echo '
'; for ($i = 0; $i < 7; $i + +) {echo '
'. $week [$i]. ' | ';} echo '
'; Echo '
'; for ($j = 0; $j < $start _weekday; $j + +) {echo '
';} while ($k & Lt;= $days) {if ($k = = $day) {echo ' |
'. $k. ' | '; }else{echo '
'. $k. ' | '; } if (($j + 1)% 7 = = 0) {echo '
'; } $j + +; $k + +; } while ($j% 7 = 0) {echo '
'; $j + +; } echo ' |
'; Echo '
'; Echo '
'. ' << '. ' | '; 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";
}
?>
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/924540.html www.bkjia.com true http://www.bkjia.com/PHPjc/924540.html techarticle Two PHP Date control class instances, PHP Date class Examples This article describes two PHP date control classes. Share to everyone for your reference. The specific analysis is as follows: Because the work needs me to find ...