Two PHP date control class instances, PHP Date class instance _php tutorial

Source: Internet
Author: User

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 " "; } 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 ();
?>
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 ' '; Echo ' '; for ($i = 0; $i < 7; $i + +) {echo ' ';} echo ' '; Echo ' '; for ($j = 0; $j < $start _weekday; $j + +) {echo ' '; }else{echo ' '; } if (($j + 1)% 7 = = 0) {echo ' '; } $j + +; $k + +; } while ($j% 7 = 0) {echo ' '; Echo ' '; Echo ' '; echo " '; Echo ' '; echo " '; echo " '; Echo ' '; Echo '
$year. ' Year ' $month. ' Month '. '
'. $week [$i]. '
';} while ($k & Lt;= $days) {if ($k = = $day) {echo ' '. $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";
}

?>

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 ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.