Php calendar production code sharing _ PHP Tutorial

Source: Internet
Author: User
Php calendar production code sharing. The code for copying calendar. class. php is as follows :? PhpclassCalendar {private $ year; current year private $ month; current month private $ start_weekday;

Calendar. class. php

The code is as follows:


Class Calendar {
Private $ year; // current year
Private $ month; // The Current month
Private $ start_weekday; // The Day of the month corresponds to the day of the week
Private $ days; // The total number of days in the current month

Function _ construct (){
$ This-> year = isset ($ _ GET ["year"])? $ _ GET ["year"]: date ("Y ");
$ This-> month = isset ($ _ GET ["month"])? $ _ GET ["month"]: date ("m ");

$ This-> start_weekday = date ("w", mktime (0, 0, 0, $ this-> month, 1, $ this-> year ));
$ This-> days = date ("t", mktime (0, 0, 0, $ this-> month, 1, $ this-> year ));
}

Function out (){
Echo'





';$ This-> chageDate ("test. php ");$ This-> weeksList ();$ This-> daysList ();Echo'
';
}

Private function weeksList (){
$ Week = array ('day', 'yi', '2', '3', '4', '5', '6 ');

Echo'';
For ($ I = 0; $ I Echo''. $ Week [$ I].'';

Echo'';
}

Private function daysList (){
Echo'';
// Output space (the space should be blank before the first day of October January)
For ($ j = 0; $ j <$ this-> start_weekday; $ j ++)
Echo' ';


For ($ k = 1; $ k <= $ this-> days; $ k ++ ){
$ J ++;
If ($ k = date ('D '))
Echo''. $ K .'';
Else
Echo''. $ K .'';

If ($ j % 7 = 0)
Echo'';

}

// A few spaces
While ($ j % 7! = 0 ){
Echo' ';
$ J ++;
}

Echo'';
}

Private function prevYear ($ year, $ month ){
$ Year = $ year-1;

If ($ year <1970)
$ Year = 1970;

Return "year = {$ year} & month = {$ month }";
}


Private function prevMonth ($ year, $ month ){
If ($ month = 1 ){
$ Year = $ year-1;

If ($ year <1970)
$ Year = 1970;

$ Month = 12;
} Else {
$ Month --;
}

Return "year = {$ year} & month = {$ month }";
}


Private function nextYear ($ year, $ month ){
$ Year = $ year + 1;

If ($ year> 2038)
$ Year = 2038;

Return "year = {$ year} & month = {$ month }";
}


Private function nextMonth ($ year, $ month ){
If ($ month = 12 ){
$ Year ++;

If ($ year> 2100)
$ Year = 2100;

$ Month = 1;
} Else {
$ Month ++;
}

Return "year = {$ year} & month = {$ month }";
}

Private function chageDate ($ url = ""){
Echo'';
Echo'PrevYear ($ this-> year, $ this-> month). '">'. '<'.'';
Echo'PrevMonth ($ this-> year, $ this-> month). '">'. '<'.'';
Echo'';
Echo '';
Echo'';


Echo'NextYear ($ this-> year, $ this-> month). '">'. '> '.'';
Echo'NextMonth ($ this-> year, $ this-> month). '">'. '> '.'';
Echo'';
}

}
?>

Test. php

The code is as follows:



Include "calendar. class. php ";

$ Calendar = new Calendar;

$ Calendar-> out ();
?>

The http://www.bkjia.com/PHPjc/718612.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/718612.htmlTechArticlecalendar.class.php code is as follows :? Php class Calendar {private $ year; // the current year private $ month; // The Current month private $ start_weekday; // The first day of the current month...

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.