万利平台新是真的吗-2019温州中考总分

首页

AD联系:507867812

万利平台新是真的吗

时间:2019-11-19 01:44:45 作者:皇冠足球赔率网 浏览量:42832

万利平台新是真的吗

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

php calender(日历)二个版本代码示例(解决2038问题)php calender(日历)二个版本代码示例(解决2038问题)

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

php calender(日历)二个版本代码示例(解决2038问题)php calender(日历)二个版本代码示例(解决2038问题),见下图

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

php calender(日历)二个版本代码示例(解决2038问题)

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

,见下图

php calender(日历)二个版本代码示例(解决2038问题)

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

php calender(日历)二个版本代码示例(解决2038问题),如下图

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

php calender(日历)二个版本代码示例(解决2038问题)

php calender(日历)二个版本代码示例(解决2038问题)

如下图

php calender(日历)二个版本代码示例(解决2038问题),如下图

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

,见图

万利平台新是真的吗php calender(日历)二个版本代码示例(解决2038问题)

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

php calender(日历)二个版本代码示例(解决2038问题)

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

php calender(日历)二个版本代码示例(解决2038问题)php calender(日历)二个版本代码示例(解决2038问题)php calender(日历)二个版本代码示例(解决2038问题)

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

php calender(日历)二个版本代码示例(解决2038问题)

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

php calender(日历)二个版本代码示例(解决2038问题)php calender(日历)二个版本代码示例(解决2038问题)

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

php calender(日历)二个版本代码示例(解决2038问题)

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

php calender(日历)二个版本代码示例(解决2038问题)php calender(日历)二个版本代码示例(解决2038问题)php calender(日历)二个版本代码示例(解决2038问题)。

php calender(日历)二个版本代码示例(解决2038问题)

万利平台新是真的吗

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

php calender(日历)二个版本代码示例(解决2038问题)

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

php calender(日历)二个版本代码示例(解决2038问题)php calender(日历)二个版本代码示例(解决2038问题)。

php calender(日历)二个版本代码示例(解决2038问题)

1.

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

php calender(日历)二个版本代码示例(解决2038问题)php calender(日历)二个版本代码示例(解决2038问题)php calender(日历)二个版本代码示例(解决2038问题)

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

php calender(日历)二个版本代码示例(解决2038问题)

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

php calender(日历)二个版本代码示例(解决2038问题)

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

php calender(日历)二个版本代码示例(解决2038问题)php calender(日历)二个版本代码示例(解决2038问题)

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

2.php calender(日历)二个版本代码示例(解决2038问题)。

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

php calender(日历)二个版本代码示例(解决2038问题)

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

php calender(日历)二个版本代码示例(解决2038问题)

3.

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

php calender(日历)二个版本代码示例(解决2038问题)

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

php calender(日历)二个版本代码示例(解决2038问题)

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

php calender(日历)二个版本代码示例(解决2038问题)php calender(日历)二个版本代码示例(解决2038问题)

4.php calender(日历)二个版本代码示例(解决2038问题)。

php calender(日历)二个版本代码示例(解决2038问题)

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

php calender(日历)二个版本代码示例(解决2038问题)php calender(日历)二个版本代码示例(解决2038问题)

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

php calender(日历)二个版本代码示例(解决2038问题)php calender(日历)二个版本代码示例(解决2038问题)php calender(日历)二个版本代码示例(解决2038问题)。万利平台新是真的吗

展开全文
相关文章
澳门专业不锈钢编织网定制

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

澳门威尼斯400888网址

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

....

巨人娱乐一线路检测 email

php calender(日历)二个版本代码示例(解决2038问题)....

内蒙古优秀影音娱乐价格

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

....

manbetx官网手机登入

php calender(日历)二个版本代码示例(解决2038问题)....

相关资讯
糖果派对游戏平台

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

....

澳门2016一元存款送彩金

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

....

亳州林肯商务车定制改装费用

注意32位机有2038问题,所以32位服务器的年限范围1970年~2038年

我们还可以使用DateTime来规避这个问题(这样与32位64位无关了)

复制代码 代码如下:<?php/*** * 我的日历* 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 ) );//是否是32位机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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = date ( 'Y-m-j' );//当月最后一天$lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

/*** * 检测是否是32位机* @author fc_lamp* @blog: fc-lamp.blog.163.com*/function is32(){$is32 = False;if (strtotime ( '2039-10-10' ) === False){$is32 = True;}return $is32;}

使用DateTime 类解决2038问题,这样不分32位与64位,代码如下:

复制代码 代码如下:<?php/*** * 我的日历(DateTime版本)* 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' );}//上一年$pretYear = $year - 1;//上一月$mpYear = $year;$preMonth = $month - 1;if ($preMonth <= 0){$preMonth = 1;$mpYear = $pretYear;}//下一年$nextYear = $year + 1;//下一月$mnYear = $year;$nextMonth = $month + 1;if ($nextMonth > 12){$nextMonth = 1;$mnYear = $nextYear;}//日历头$html = <<<HTML<table width="500" border="1"> <tr align="center"> <td><a href="?y=$pretYear">上一年</a></td> <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td> <td><a href="?">回到今天</a></td> <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td><td><a href="?y=$nextYear">下一年</a></td> </tr> <tr align="center"> <td colspan="5">{$year}年{$month}月</td> </tr> <tr> <td colspan="5"><table width="100%" border="1"><tr align="center"><td style="background-color:#DAF0DD;">星期一</td><td style="background-color:#DAF0DD;">星期二</td><td style="background-color:#DAF0DD;">星期三</td><td style="background-color:#DAF0DD;">星期四</td><td style="background-color:#DAF0DD;">星期五</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td><td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td></tr>HTML;$currentDay = $nowDate->format('Y-m-j' );//当月最后一天$creatDate = new DateTime("$year-$nextMonth-0");$lastday = $creatDate->format('j');$creatDate = NULL;//循环输出天数$day = 1;$line = '';while ( $day <= $lastday ){$cday = $year . '-' . $month . '-' . $day;//当前星期几$creatDate = new DateTime("$year-$month-$day");$nowWeek = $creatDate->format('N');$creatDate = NULL;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>";//一周结束if ($nowWeek == 7){$line .= '</tr>';$html .= $line;$line = '<tr align="center">';}//全月结束if ($day == $lastday){if ($nowWeek != 7){$line .= str_repeat ( '<td></td>', 7 - $nowWeek );}$line .= '</tr>';$html .= $line;break;}$day ++;}$html .= <<<HTML</table></td> </tr></table>HTML;return $html;}

....

热门资讯