A simple phpCalender (calendar) solves the 2038 problem, which can be used on both 32-bit and 64-bit machines. The code is very simple and easy to modify.
A simple php Calender (calendar) solves the 2038 problem, which can be used on both 32-bit and 64-bit machines. The code is very simple and easy to modify.
Note that the 32-bit server has 2038 problems, so the 32-bit server's validity period ranges from ~ 2038
We can also use DateTime to avoid this problem (this is irrelevant to 32-bit 64-bit)
The Code is as follows:
/**
*
* My Calendar
* Date_default_timezone_set date mktime
* @ Param int $ year
* @ Param int $ month
* @ Param string $ timezone
* @ Author fc_lamp
* @ Blog: fc-lamp.blog.163.com
*/
Function myCalender ($ year = '', $ month ='', $ timezone = 'Asia/Shanghai ')
{
Date_default_timezone_set ($ timezone );
$ Year = abs (intval ($ year ));
$ Month = abs (intval ($ month ));
// Whether it is a 32-bit Server
If (is32 ())
{
If ($ year <1970 or $ year> = 2038)
{
$ Year = date ('y ');
}
} Else
{
If ($ year <= 0)
{
$ Year = date ('y ');
}
}
If ($ month <= 0 or $ month> 12)
{
$ Month = date ('M ');
}
// Previous year
$ PretYear = $ year-1;
// Last month
$ MpYear = $ year;
$ PreMonth = $ month-1;
If ($ preMonth <= 0)
{
$ PreMonth = 1;
$ MpYear = $ pretYear;
}
// Next year
$ NextYear = $ year + 1;
// Next month
$ MnYear = $ year;
$ NextMonth = $ month + 1;
If ($ nextMonth> 12)
{
$ NextMonth = 1;
$ MnYear = $ nextYear;
}
// Calendar Header
$ Html = <
Last year |
Last month |
Back to today |
Next month |
Next year |
{$ Year}-{$ month} month |
Monday |
Tuesday |
Wednesday |
Thursday |
Friday |
Saturday |
Sunday |
HTML;$ CurrentDay = date ('Y-m-J ');// Last day of the month$ Lastday = date ('J', mktime (0, 0, 0, $ nextMonth, 0, $ year ));// Number of days of cyclic output$ Day = 1;$ Line = '';While ($ day <= $ lastday){$ Cday = $ year. '-'. $ month. '-'. $ day;// Current day of the week$ NowWeek = date ('n', mktime (0, 0, 0, $ month, $ day, $ year ));If ($ day = 1){$ Line ='
';$ Line. = str_repeat ('
| ', $ NowWeek-1 );}If ($ cday = $ currentDay){$ Style = 'style = "color: red ;"';} Else{$ Style = '';}$ Line. ="
$ Day | ";// End of one weekIf ($ nowWeek = 7){$ Line. ='
';$ Html. = $ line;$ Line ='
';}// End of the whole monthIf ($ day = $ lastday){If ($ nowWeek! = 7){$ Line. = str_repeat ('
| ', 7-$ nowWeek );}$ Line. ='
';$ Html. = $ line;Break;}$ Day ++;}$ Html. = <
|
HTML;
Return $ html;
}
/**
*
* Check whether it is a 32-bit server.
* @ Author fc_lamp
* @ Blog: fc-lamp.blog.163.com
*/
Function is32 ()
{
$ Is32 = False;
If (strtotime ('2017-10-10 ') = False)
{
$ Is32 = True;
}
Return $ is32;
}
Use the DateTime class to solve the 2038 problem. The Code is as follows:
The Code is as follows: