Two php date control instances _ PHP-php Tutorial

Source: Internet
Author: User
This article mainly introduces two php date control classes, including detailed style control and usage methods, which are very useful. if you need them, you can refer to the following examples to illustrate two php date control classes. Share it with you for your reference. The specific analysis is as follows:

Because I have to find two time and date controls for my work, I don't need to implement js as long as php is used, because I want to refer to the query operations. if you are interested, please refer to them, I used the second one myself, so the second one was modified.

Example 1: The code is as follows:

The 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 2: The code is as follows:

The code is as follows:

<? 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 ('day', 'yi', '2', '3', '4', '5', '6 ');
$ 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. 'year'. $ month. '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 ";
}

?>

I hope this article will help you with php programming.

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.