We can also use DateTime to circumvent this problem (this has nothing to do with 32-bit 64-bit)
<?php
/**
*
* 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 machine
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 ');
}
Last 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 = <<<table width= "border=" 1 ">
<TR align= "center" >
<td><a href= "? y= $pretYear" > Last year </a></td>
<td><a href= "? y= $mpYear &m= $preMonth" > Last month </a></td>
<td><a href= "?" > Back to Today </a></td>
<td><a href= "? y= $mnYear &m= $nextMonth" > next month </a></td>
<td><a href= "? y= $nextYear" > next year </a></td>
</tr>
<TR align= "center" >
<TD colspan= "5" >{$year} year {$month} month </td>
</tr>
<tr>
<TD colspan= "5" >
<table width= "100%" border= "1" >
<TR align= "center" >
<TD style= "Background-color: #DAF0DD;" > Monday </td>
<TD style= "Background-color: #DAF0DD;" > Tuesday </td>
<TD style= "Background-color: #DAF0DD;" > Wednesday </td>
<TD style= "Background-color: #DAF0DD;" > Thursday </td>
<TD style= "Background-color: #DAF0DD;" > Friday </td>
<TD style= "Background-color: #F60; color: #fff; font-weight:bold;" > Saturday </td>
<TD style= "Background-color: #F60; color: #fff; font-weight:bold;" > Sunday </td>
</tr>
HTML;
$currentDay = Date (' Y-m-j ');
The last day of the month
$lastday = Date (' J ', Mktime (0, 0, 0, $nextMonth, 0, $year));
Cycle Output Days
$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 = ' <tr align= ' center ' > ';
$line. = Str_repeat (' <td> </td> ', $nowWeek-1);
}
if ($cday = = $currentDay)
{
$style = ' style= ' color:red; "';
} else
{
$style = ';
}
$line. = "<td $style > $day </td>";
The end of a week
if ($nowWeek = = 7)
{
$line. = ' </tr> ';
$html. = $line;
$line = ' <tr align= ' center ' > ';
}
All month End
if ($day = = $lastday)
{
if ($nowWeek!= 7)
{
$line. = Str_repeat (' <td> </td> ', 7-$nowWeek);
}
$line. = ' </tr> ';
$html. = $line;
Break
}
$day + +;
}
$html. = <<</table>
</td>
</tr>
</table>
HTML;
return $html;
}
/**
*
* Detect whether it is 32-bit machine
* @author Fc_lamp
* @blog: fc-lamp.blog.163.com
*/
function Is32 ()
{
$is = False;
if (Strtotime (' 2039-10-10 ') = = False)
{
$is = True;
}
return $is 32;
}
Use the DateTime class to troubleshoot 2038 problems, which are no more than 32 bits and 64 bits, as follows: