当前位置:Gxlcms > PHP教程 > phpCalender日历)代码

phpCalender日历)代码

时间:2021-07-01 10:21:17 帮助过:56人阅读

  1. <!--?php
  2. /**
  3. *
  4. * 我的日历
  5. * date_default_timezone_set date mktime
  6. * @param int $year
  7. * @param int $month
  8. * @param string $timezone
  9. * @author fc_lamp
  10. * @blog: http://www.cnblogs.com/roucheng/
  11. */
  12. function myCalender($year = '', $month = '', $timezone = 'Asia/Shanghai')
  13. {
  14. date_default_timezone_set ( $timezone );
  15. $year = abs ( intval ( $year ) );
  16. $month = abs ( intval ( $month ) );
  17. //是否是32位机
  18. if (is32())
  19. {
  20. if ($year < 1970 or $year -->= 2038)
  21. {
  22. $year = date ( 'Y' );
  23. }
  24. } else
  25. {
  26. if ($year <= 0)
  27. {
  28. $year = date ( 'Y' );
  29. }
  30. }
  31. if ($month <= 0 or $month > 12)
  32. {
  33. $month = date ( 'm' );
  34. }
  35. //上一年
  36. $pretYear = $year - 1;
  37. //上一月
  38. $mpYear = $year;
  39. $preMonth = $month - 1;
  40. if ($preMonth <= 0)
  41. {
  42. $preMonth = 1;
  43. $mpYear = $pretYear;
  44. }
  45. //下一年
  46. $nextYear = $year + 1;
  47. //下一月
  48. $mnYear = $year;
  49. $nextMonth = $month + 1;
  50. if ($nextMonth > 12)
  51. {
  52. $nextMonth = 1;
  53. $mnYear = $nextYear;
  54. }
  55. //日历头
  56. $html = <<
  57. 上一年
  58. 上一月
  59. 回到今天
  60. 下一月
  61. 下一年
  62. {$year}年{$month}月
  63. HTML;
  64. $currentDay = date ( 'Y-m-j' );
  65. //当月最后一天
  66. $lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );
  67. //循环输出天数
  68. $day = 1;
  69. $line = '';
  70. while ( $day <= $lastday )
  71. {
  72. $cday = $year . '-' . $month . '-' . $day;
  73. //当前星期几
  74. $nowWeek = date ( 'N', mktime ( 0, 0, 0, $month, $day, $year ) );
  75. if ($day == 1)
  76. {
  77. $line = '';
  78. $line .= str_repeat ( '', $nowWeek - 1 );
  79. }
  80. if ($cday == $currentDay)
  81. {
  82. $style = 'style="color:red;"';
  83. } else
  84. {
  85. $style = '';
  86. }
  87. $line .= "";
  88. //一周结束
  89. if ($nowWeek == 7)
  90. {
  91. $line .= '';
  92. $html .= $line;
  93. $line = '';
  94. }
  95. //全月结束
  96. if ($day == $lastday)
  97. {
  98. if ($nowWeek != 7)
  99. {
  100. $line .= str_repeat ( '', 7 - $nowWeek );
  101. }
  102. $line .= '';
  103. $html .= $line;
  104. break;
  105. }
  106. $day ++;
  107. }
  108. $html .= <<<table width="100%" border="1">
  109. <tbody><tr align="center">
  110. <td>星期一</td>
  111. <td>星期二</td>
  112. <td>星期三</td>
  113. <td>星期四</td>
  114. <td>星期五</td>
  115. <td>星期六</td>
  116. <td>星期天</td>
  117. </tr><tr align="center"><td> </td><td $style="">$day</td></tr><tr align="center"><td> </td></tr>
  118. </tbody></table>
  119. HTML;
  120. return $html;
  121. }
  122. /**
  123. *
  124. * 检测是否是32位机
  125. * @author fc_lamp
  126. * @blog: fc-lamp.blog.163.com
  127. */
  128. function is32()
  129. {
  130. $is32 = False;
  131. if (strtotime ( '2039-10-10' ) === False)
  132. {
  133. $is32 = True;
  134. }
  135. return $is32;
  136. }

以上就介绍了php Calender日历)代码,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

人气教程排行