Note 32-bit machines have 2038 issues, so the age range of 32-bit servers 1970 ~2038
We can also use DateTime to circumvent this problem (this has nothing to do with 32-bit 64-bit)
Copy CodeThe 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 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 = << <>
Last year |
Last month |
Back to today |
Next month |
Next year |
{$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));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 = '
'; $line. = Str_repeat ('
| ', $nowWeek-1); } if ($cday = = $currentDay) {$style = ' style= ' color:red; ';} else {$style = ';} $line. = "
$day | "; End of Week if ($nowWeek = = 7) {$line. = '
';$html. = $line;$line = '
'; }//All-month End if ($day = = $lastday) {if ($nowWeek! = 7) {$line. = Str_repeat ('
| ', 7-$nowWeek); } $line. = '
';$html. = $line;Break}$day + +;}$html. = <<
|
HTML;
return $html;
}
/**
*
* Check if it is a 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 solve the 2038 problem, so that there is no 32-bit and 64-bit, the code is as follows:
Copy CodeThe code is as follows:
/**
*
* My Calendar (DateTime version)
* 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));
$nowDate = new DateTime ();
if ($year <= 0)
{
$year = $nowDate->format (' Y ');
}
if ($month <= 0 or $month > 12)
{
$month = $nowDate->format (' 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 = << <>
Last year |
Last month |
Back to today |
Next month |
Next year |
{$year} year {$month} month |
<>
Monday |
Tuesday |
Wednesday |
Thursday |
Friday |
Saturday |
Sunday |
HTML;$currentDay = $nowDate->format (' y-m-j ');Last day of the month$creatDate = new DateTime ("$year-$nextMonth-0");$lastday = $creatDate->format (' J ');$creatDate = NULL;Cycle Output Days$day = 1;$line = ";while ($day <= $lastday){$cday = $year. '-' . $month. '-' . $day;Current day of the week$creatDate = new DateTime ("$year-$month-$day");$nowWeek = $creatDate->format (' N ');$creatDate = NULL;if ($day = = 1){$line = '
'; $line. = Str_repeat ('
| ', $nowWeek-1); } if ($cday = = $currentDay) {$style = ' style= ' color:red; ';} else {$style = ';} $line. = "
$day | "; End of Week if ($nowWeek = = 7) {$line. = '
';$html. = $line;$line = '
'; }//All-month End if ($day = = $lastday) {if ($nowWeek! = 7) {$line. = Str_repeat ('
| ', 7-$nowWeek); } $line. = '
';$html. = $line;Break}$day + +;}$html. = <<
|
HTML;
return $html;
}
http://www.bkjia.com/PHPjc/621670.html www.bkjia.com true http://www.bkjia.com/PHPjc/621670.html techarticle Note 32-bit machine has 2038 problems, so the 32-bit server's age range 1970 ~2038 We can also use DateTime to circumvent this problem (this is unrelated to the 32-bit 64-bit) copy code code such as ...