Two php date control classes. 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, because of my work, I have to find two time and date controls. I don't need to use JavaScript to implement them as long as php. I have to perform operations for reference queries. if you need them, please refer to them, I use the second one myself, so the second one has been modified.
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"
|
". $ Weekarray [$ k]." | ";}Echo"
"; For ($ I = 0; $ I <= 5; $ I ++){Echo"
";For ($ j = 1; $ j <= 7; $ j ++){$ Math = ($ j-$ this-> oneday_week () + 7 * $ I; Echo"
|
";
If ($ math <= $ this-> endday () and $ math> = 1)
{
Echo $ math;
}
Echo" | ";}Echo"
";}Echo"
";
}
}
/* $ Calendar = new Calendar ($ _ GET ['Year'], $ _ GET ['month']);
// $ Calendar-> month = $ _ GET ['month'];
// $ Calendar-> year =$ _ GET ['Year'];
$ Calendar-> Show_Calendar ();*/
// Second
?>
Instance 2
Header ("content-type: text/html; charset = utf-8 ");
?>
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'
Echo'
';Echo'
| '. $ Year. 'year'. $ month. 'month '.' |
';Echo'
';For ($ I = 0; $ I <7; $ I ++ ){Echo'
| '. $ Week [$ I].' | ';}Echo'
';Echo'
';For ($ j = 0; $ j <$ start_weekday; $ j ++ ){Echo'
| '. $ J .' | ';}While ($ k <= $ days ){If ($ k = $ day ){Echo'
'. $ K .' | ';} Else {Echo'
'. $ K .' | ';}If ($ j + 1) % 7 = 0 ){Echo'
';}$ J ++;$ K ++;}While ($ j % 7! = 0 ){Echo'
| '. $ J .' | ';$ J ++;}Echo'
';
';Echo"
| ". '<'.' | ';Echo"
". '<'.' | ';Echo'
';
Echo '';
Echo' | ';Echo"
". '> '.' | ';Echo"
". '> '.' | ';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 ";
}
?>
...