One date class-PHP source code

Source: Internet
Author: User
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. ="
  
  "; $ S. =" 
    "; $ S. =" 
    "; $ S. =" 
   "; $ S. =" 
   
     "; $ S. =" 
    "; $ S. =" 
    "; $ S. =" 
    "; $ S. =" 
    "; $ S. =" 
    "; $ S. =" 
    "; $ S. =" 
    "; $ 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. =" 
    "; $ D ++;} $ s. =" 
   ";} /*************************************** **************************************** * ******/$ S. =" 
  
". ($ PrevMonth = "")? "": "<")."$ Header". ($ NextMonth = "")? "": "> ")."
". $ This-> dayNames [($ this-> startDay) % 7]."". $ This-> dayNames [($ this-> startDay + 1) % 7]."". $ This-> dayNames [($ this-> startDay + 2) % 7]."". $ This-> dayNames [($ this-> startDay + 3) % 7]."". $ This-> dayNames [($ this-> startDay + 4) % 7]."". $ This-> dayNames [($ this-> startDay + 5) % 7]."". $ This-> dayNames [($ this-> startDay + 6) % 7]."
"; 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. ="
"; Return $ s;} // declare an HTMLfunction getYearHTML ($ year) {$ s =" "; $ prev = $ this-> getCalendarLink (0, $ year-1); $ next = $ this-> getCalendarLink (0, $ year + 1); $ s. =" "; $ S. =" "; $ S. =" "; $ S. =" "; $ S. =" "; $ S. =" "; $ S. =" "; $ S. =" "; $ S. =" "; $ S. =" "; $ S. =" "; $ S. =" "; $ S. =" "; $ S. =" "; $ S. =" "; $ S. =" "; $ S. =" "; $ S. =" "; $ S. =" "; $ S. =" "; $ S. =" "; $ S. =" "; $ S. =" "; $ S. =" "; $ S. =" "; $ S. =" "; $ S. ="
". ($ Prev = "")? "": "<")."". ($ This-> startMonth> 1 )? $ Year. "-". ($ year + 1): $ year )."". ($ Next = "")? "": "> ")."
". $ This-> getMonthHTML (0 + $ this-> startMonth, $ year, 0 )."". $ This-> getMonthHTML (1 + $ this-> startMonth, $ year, 0 )."". $ This-> getMonthHTML (2 + $ this-> startMonth, $ year, 0 )."
". $ This-> getMonthHTML (3 + $ this-> startMonth, $ year, 0 )."". $ This-> getMonthHTML (4 + $ this-> startMonth, $ year, 0 )."". $ This-> getMonthHTML (5 + $ this-> startMonth, $ year, 0 )."
". $ This-> getMonthHTML (6 + $ this-> startMonth, $ year, 0 )."". $ This-> getMonthHTML (7 + $ this-> startMonth, $ year, 0 )."". $ This-> getMonthHTML (8 + $ this-> startMonth, $ year, 0 )."
". $ This-> getMonthHTML (9 + $ this-> startMonth, $ year, 0 )."". $ This-> getMonthHTML (10 + $ this-> startMonth, $ year, 0 )."". $ This-> getMonthHTML (11 + $ this-> startMonth, $ year, 0 )."
"; 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 )!

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.