Because I have to find two time and date controls for my work, I don't need to implement js as long as php, because I want to perform operations with reference queries. If I need them, I can refer to them, I use the second one myself, so the second one has been modified.
<? Php tutorial
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 = "<td colspan = '2'> <div align = 'center'> <a href = $ PHP_SELF? Year = ". $ lastyear." & month = ". $ lastmonth." & ><</a> </div> </td> ";
$ Str. = "<td colspan = '3'> <div align = 'center'> ". $ this-> year. "--". $ this-> month. "</div> </td> ";
$ Str. = "<td colspan = '2'> <div align = 'center'> <a href = $ PHP_SELF? Year = ". $ nextyear." & month = ". $ nextmonth." & >>></a> </div> </td> ";
Return $ str;
}
Function Show_Calendar ()
{
Echo "<table width = '000000' border = 5> <tr class = 'tr. title '> ". $ this-> title_link (). "</tr> <tr> ";
$ Weekarray = array ("day", "one", "two", "three", "four", "five", "Six ");
For ($ k = 0; $ k <= 6; $ k ++)
{
Echo "<td> <div align = 'center'>". $ weekarray [$ k]. "</div> </td> ";
}
Echo "</tr> ";
For ($ I = 0; $ I <= 5; $ I ++)
{
Echo "<tr> ";
For ($ j = 1; $ j <= 7; $ j ++)
{
$ Math = ($ j-$ this-> oneday_week () + 7 * $ I;
Echo "<td> <div align = 'center'> ";
If ($ math <= $ this-> endday () and $ math> = 1)
{
Echo $ math;
}
Echo "</div> </td> ";
}
Echo "</tr> ";
}
Echo "</table> ";
}
}
/* $ Calendar = new Calendar ($ _ GET ['Year'], $ _ GET ['month']);
// $ Calendar-> month = $ _ GET ['month'];
// $ Calendar-> year =$ _ GET ['Year'];
$ Calendar-> Show_Calendar ();*/
// Second
?>
Instance 2
<? Php
Header ("content-type: text/html; charset = UTF-8 ");
?>
<Meta http-equiv = "content-type" content = "text/html; charset = UTF-8">
<Link href = "statics/css tutorial/zhaoshang.css" rel = "stylesheet" type = "text/css">
<Div class = "rili">
<? Php
If (! Empty ($ _ 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 (empty ($ year )){
$ Year = date ('y ');
}
If (empty ($ month )){
$ Month = date ('M ');
}
If (empty ($ 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 '<table> ';
Echo '<tr> <td colspan = 7 style = "text-align: center; width: 250px; background: # d5e5f6; border-bottom: 1px solid #333366; "> '. $ year. 'Year '. $ month. 'month '. '</td> </tr> ';
Echo '<tr> ';
For ($ I = 0; $ I <7; $ I ++ ){
Echo '<td>'. $ week [$ I]. '</td> ';
}
Echo '</tr> ';
Echo '<tr> ';
For ($ j = 0; $ j <$ start_weekday; $ j ++ ){
Echo '<td style = "color: # f1f8fc;">'. $ j. '</td> ';
}
While ($ k <= $ days ){
If ($ k = $ day ){
Echo '<td style = "color: red"> <a href = "? Year = '. $ year. '& month = '. $ month. '& day = '. $ k. '"> <span style =" color: red "> '. $ k. '</span> </a> </td> ';
} Else {
Echo '<td> <a href = "? Year = '. $ year. '& month = '. $ month. '& day = '. $ k. '"> '. $ k. '</a> </td> ';
}
If ($ j + 1) % 7 = 0 ){
Echo '</tr> <tr> ';
}
$ J ++;
$ K ++;
}
While ($ j % 7! = 0 ){
Echo '<td style = "color: # f1f8fc;">'. $ j. '</td> ';
$ J ++;
}
Echo '</tr> ';
Echo '<tr style = "background: # d5e5f6;"> ';
Echo "<td> <a href =? ". LastYear ($ year, $ month)."> ". '<'. '</a> </td> ';
Echo "<td> <a href =? ". LastMonth ($ year, $ month)."> ". '<'. '</a> </td> ';
Echo '<td colspan = 3 style = "width: 105px;"> ';
Echo '<form name = "myform" method = "GET"> ';
Echo '<select name = year class = "year"> ';
For ($ start_year = 1970; $ start_year <2039; $ start_year ++ ){
$ Selected = '';
If ($ year = $ start_year) {$ selected = 'selected ';}
Echo '<option value ='. $ start_year. ''. $ selected. '>'. $ start_year. '</option>'." nt ";
}
Echo '</select> ';
Echo '<select name = month class = "month"> ';
For ($ start_month = 1; $ start_month <= 12; $ start_month ++ ){
$ Selected = '';
If ($ month = $ start_month) {$ selected = 'selected ';}
Echo '<option value ='. $ start_month. ''. $ selected. '>'. $ start_month. '</option>'." nt ";
}
Echo '</select> ';
/* Echo 'month ';*/
/* Echo '<input type = "submit" name = "search" value = "query"> ';*/
Echo '</form> ';
Echo '</td> ';
Echo "<td> <a href =? ". NextYear ($ year, $ month)."> ". '>'. '</a> </td> ';
Echo "<td> <a href =? ". NextMonth ($ year, $ month)."> ". '>'. '</a> </td> ';
Echo '</tr> ';
Echo '</table> ';
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 ";
}
?>
</Div>