A date class
A date class
January","February","March","Else L","May","June","July","August","September","October","November","December"); Var $ daysInMonth = array (31, 28, 31, 30, 31, 30, 31, 31, 30, 31); function setDayNames ($ names) {$ this-> dayNames = $ names;} function getDayNames () {return $ this-> dayNames;} function setMonthNames ($ names) {$ this-> monthNames = $ names;} function getMonthNames () {return $ this-> monthNames;} function setStartDay ($ day) {$ this-> startDay = $ day;} // function for obtaining the start date getStartDay () {return $ this-> startDay;} functio N setStartMonth ($ month) {$ this-> startMonth = $ month;} function getStartMonth () {return $ this-> startMonth;} function getCalendarLink ($ month, $ year) {return "";} // declare a function getDateLink ($ day, $ month, $ year) {$ link = "counter. php? Day = $ day & month = $ month & year = $ year & fromcounter = 1 "; return" $ link ";}// set the date link function getCurrentMonthView () {$ d = getdate (time (); return $ this-> getMonthView ($ d ["mon"], $ d ["year"]);} // Obtain the current year function getCurrentYearView () {$ d = getdate (time (); return $ this-> getYearView ($ d ["year"]);} // declare a function getMonthView ($ month, $ year) for obtaining the specified year and month {return $ this-> getMonthHTML ($ month, $ year );} // declare a function to obtain the month information of a specified year. getYearView ($ Year) {return $ this-> getYearHTML ($ year);} // get the number of days of a month function getDaysInMonth ($ month, $ year) {if ($ month <1 | $ month> 12) {return 0;} $ d = $ this-> daysInMonth [$ month-1]; if ($ month = 2) {if ($ year % 4 = 0) {if ($ year % 100 = 0) {if ($ year % 400 = 0) {$ d = 29 ;}} else {$ d = 29 ;}} return $ d ;} // declare the getMonthHTML function getMonthHTML ($ m, $ y, $ showYear = 1) {$ s = ""; $ a = $ this-> adjustDate ($ m, $ y); $ month = $ a [0]; $ year = $ a [1]; $ daysInMonth = $ this-> ge TDaysInMonth ($ month, $ year); $ date = getdate (mktime (12, 0, 0, $ month, 1, $ year )); $ first = $ date ['wday']; $ monthName = $ this-> monthNames [$ month-1]; $ prev = $ this-> adjustDate ($ month-1, $ year); $ next = $ this-> adjustDate ($ month + 1, $ year); if ($ showYear = 1) {$ prevMonth = $ this-> getCalendarLink ($ prev [0], $ prev [1]); $ nextMonth = $ this-> getCalendarLink ($ next [0], $ next [1]);} else {$ prevMonth = ""; $ nextMonth = "" ;}$ header = $ monthName. ($ showYear> 0 )?"". $ Year :""); $ S. ="
"; $ S. ="
". ($ PrevMonth = "")? "": "<")." | "; $ S. ="
$ Header | "; $ S. ="
". ($ NextMonth = "")? "": "> ")." | "; $ S. ="
"; $ S. ="
"; $ S. ="
". $ This-> dayNames [($ this-> startDay) % 7]." | "; $ S. ="
". $ This-> dayNames [($ this-> startDay + 1) % 7]." | "; $ S. ="
". $ This-> dayNames [($ this-> startDay + 2) % 7]." | "; $ S. ="
". $ This-> dayNames [($ this-> startDay + 3) % 7]." | "; $ S. ="
". $ This-> dayNames [($ this-> startDay + 4) % 7]." | "; $ S. ="
". $ This-> dayNames [($ this-> startDay + 5) % 7]." | "; $ S. ="
". $ This-> dayNames [($ this-> startDay + 6) % 7]." | "; $ S. ="
"; ***** **************************************** * ***/$ D = $ this-> startDay + 1-$ first; while ($ d> 1) {$ d-= 7 ;}$ today = getdate (time (); while ($ d <=$ daysInMonth) {$ s. ="
"; For ($ I = 0; $ I <7; $ I ++) {$ class = ($ year = $ today ['Year'] & $ month = $ today ['mon'] & $ d = $ today ['mday '])? "CalenderToday": "calendar"; $ s. ="
"; If ($ d> 0 & $ d <= $ daysInMonth) {$ link = $ this-> getDateLink ($ d, $ month, $ year ); $ mtime = mktime (); $ dnow = date ("d", $ mtime); $ mnow = date ("m", $ mtime ); if ($ dnow ==$ d & $ mnow =$ month) {$ s. = ($ link = "")? $ D :"$ D");} Else {$ s. = ($ link = "")? $ D: "$ d") ;}} else {$ s. = "" ;}$ s. =" | "; $ D ++;} $ s. ="
";} /*************************************** **************************************** * ******/$ S. ="
"; Return $ s;} // declare an HTMLfunction getYearHTML ($ year) {$ s =" "; $ prev = $ this-> getCalendarLink (0, $ year-1); $ next = $ this-> getCalendarLink (0, $ year + 1); $ s. ="
"; $ S. ="
"; $ S. ="
". ($ Prev = "")? "": "<")." | "; $ S. ="
". ($ This-> startMonth> 1 )? $ Year. "-". ($ year + 1): $ year )." | "; $ S. ="
". ($ Next = "")? "": "> ")." | "; $ S. ="
"; $ S. ="
"; $ S. ="
". $ This-> getMonthHTML (0 + $ this-> startMonth, $ year, 0 )." | "; $ S. ="
". $ This-> getMonthHTML (1 + $ this-> startMonth, $ year, 0 )." | "; $ S. ="
". $ This-> getMonthHTML (2 + $ this-> startMonth, $ year, 0 )." | "; $ S. ="
"; $ S. ="
"; $ S. ="
". $ This-> getMonthHTML (3 + $ this-> startMonth, $ year, 0 )." | "; $ S. ="
". $ This-> getMonthHTML (4 + $ this-> startMonth, $ year, 0 )." | "; $ S. ="
". $ This-> getMonthHTML (5 + $ this-> startMonth, $ year, 0 )." | "; $ S. ="
"; $ S. ="
"; $ S. ="
". $ This-> getMonthHTML (6 + $ this-> startMonth, $ year, 0 )." | "; $ S. ="
". $ This-> getMonthHTML (7 + $ this-> startMonth, $ year, 0 )." | "; $ S. ="
". $ This-> getMonthHTML (8 + $ this-> startMonth, $ year, 0 )." | "; $ S. ="
"; $ S. ="
"; $ S. ="
". $ This-> getMonthHTML (9 + $ this-> startMonth, $ year, 0 )." | "; $ S. ="
". $ This-> getMonthHTML (10 + $ this-> startMonth, $ year, 0 )." | "; $ S. ="
". $ This-> getMonthHTML (11 + $ this-> startMonth, $ year, 0 )." | "; $ S. ="
"; $ S. ="
"; Return $ s;} // declare a date adjustment function adjustDate ($ month, $ year) {$ a = array (); $ a [0] = $ month; $ a [1] = $ year; while ($ a [0]> 12) {$ a [0]-= 12; $ a [1] ++ ;} while ($ a [0] <= 0) {$ a [0] + = 12; $ a [1] --;} return $ ;}} class MyCalendar extends Calendar {function getCalendarLink ($ month, $ year) {$ s = getenv ('script _ name '); // equivalent to $ _ SERVER ['script _ name'] return "$ s? Month = $ month & year = $ year ";}}?>
The above is the content of a date class. For more information, see The PHP Chinese website (www.php1.cn )!