php Calender(日历)代码

代码如下:1=2038)23{24$year=date('Y');25}26}else27{28if($year12)36{37$

大家好,又见面了,我是全栈君,今天给大家准备了Idea注册码。

全栈程序员社区此处内容已经被作者隐藏,请输入验证码查看内容
验证码:
请关注本站微信公众号,回复“验证码”,获取验证码。在微信里搜索“全栈程序员社区”或者“www_javaforall_cn”或者微信扫描右侧二维码都可以关注本站微信公众号。

代码如下:

  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     
 15     date_default_timezone_set ( $timezone );
 16     $year = abs ( intval ( $year ) );
 17     $month = abs ( intval ( $month ) );
 18     
 19     //是否是32位机
 20     if (is32())
 21     {
 22         if ($year < 1970 or $year >= 2038)
 23         {
 24             $year = date ( 'Y' );
 25         }
 26     } else
 27     {
 28         if ($year <= 0)
 29         {
 30             $year = date ( 'Y' );
 31         }
 32     
 33     }
 34     
 35     if ($month <= 0 or $month > 12)
 36     {
 37         $month = date ( 'm' );
 38     }
 39     
 40     //上一年
 41     $pretYear = $year - 1;
 42     //上一月
 43     $mpYear = $year;
 44     $preMonth = $month - 1;
 45     if ($preMonth <= 0)
 46     {
 47         $preMonth = 1;
 48         $mpYear = $pretYear;
 49     }
 50     
 51     //下一年
 52     $nextYear = $year + 1;
 53     //下一月
 54     $mnYear = $year;
 55     $nextMonth = $month + 1;
 56     if ($nextMonth > 12)
 57     {
 58         $nextMonth = 1;
 59         $mnYear = $nextYear;
 60     }
 61     
 62     //日历头
 63     $html = <<<HTML
 64 <table width="500" border="1">
 65   <tr align="center">
 66     <td><a href="?y=$pretYear">上一年</a></td>
 67     <td><a href="?y=$mpYear&m=$preMonth">上一月</a></td>
 68      <td><a href="?">回到今天</a></td>
 69     <td><a href="?y=$mnYear&m=$nextMonth">下一月</a></td>
 70     <td><a href="?y=$nextYear">下一年</a></td>
 71   </tr>
 72   <tr align="center">
 73     <td colspan="5">{$year}年{$month}月</td>
 74   </tr>
 75   <tr>
 76       <td colspan="5">
 77         <table width="100%" border="1">
 78             <tr align="center">
 79                 <td style="background-color:#DAF0DD;">星期一</td>
 80                 <td style="background-color:#DAF0DD;">星期二</td>
 81                 <td style="background-color:#DAF0DD;">星期三</td>
 82                 <td style="background-color:#DAF0DD;">星期四</td>
 83                 <td style="background-color:#DAF0DD;">星期五</td>
 84                 <td style="background-color:#F60;color:#fff;font-weight: bold;">星期六</td>
 85                 <td style="background-color:#F60;color:#fff;font-weight: bold;">星期天</td>
 86             </tr>
 87 HTML;
 88     
 89     $currentDay = date ( 'Y-m-j' );
 90     
 91     //当月最后一天
 92     $lastday = date ( 'j', mktime ( 0, 0, 0, $nextMonth, 0, $year ) );
 93     
 94     //循环输出天数
 95     $day = 1;
 96     $line = '';
 97     while ( $day <= $lastday )
 98     {
 99         $cday = $year . '-' . $month . '-' . $day;
100         
101         //当前星期几
102         $nowWeek = date ( 'N', mktime ( 0, 0, 0, $month, $day, $year ) );
103         
104         if ($day == 1)
105         {
106             $line = '<tr align="center">';
107             $line .= str_repeat ( '<td>&nbsp;</td>', $nowWeek - 1 );
108         }
109         
110         if ($cday == $currentDay)
111         {
112             $style = 'style="color:red;"';
113         } else
114         {
115             $style = '';
116         }
117         
118         $line .= "<td $style>$day</td>";
119         
120         //一周结束
121         if ($nowWeek == 7)
122         {
123             $line .= '</tr>';
124             $html .= $line;
125             $line = '<tr align="center">';
126         }
127         
128         //全月结束
129         if ($day == $lastday)
130         {
131             if ($nowWeek != 7)
132             {
133                 $line .= str_repeat ( '<td>&nbsp;</td>', 7 - $nowWeek );
134             }
135             $line .= '</tr>';
136             $html .= $line;
137             
138             break;
139         }
140         
141         $day ++;
142     }
143     
144     $html .= <<<HTML
145         </table>    
146     </td>
147   </tr>
148 </table>
149 HTML;
150     return $html;
151 }
152 
153 /**
154  * 
155  * 检测是否是32位机
156  * @author fc_lamp
157  * @blog: fc-lamp.blog.163.com
158  */
159 function is32()
160 {
161     $is32 = False;
162     if (strtotime ( '2039-10-10' ) === False)
163     {
164         $is32 = True;
165     }
166     return $is32;
167 }

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/120753.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • mysql executereader_ExecuteReader

    mysql executereader_ExecuteReader最近在做winform的编程,想到一真没有使用过ExecuteReader。可能以前以后它的用户不大,或者不大好用,故没有用过。今天在这里将学习记录写下来,供读者参考:1、MSDN上说:SendstheCommandTexttotheConnectionandbuildsaSqlDataReader.(这句话就不翻译了)2、实例片段:[C#]publicvoidCreateM…

    2022年6月20日
    27
  • 什么是用户态和内核态_进程的用户态和内核态

    什么是用户态和内核态_进程的用户态和内核态要了解什么是用户态,什么是内核态,我们需要先了解什么是进程的用户空间和内核空间:Linux虚拟内存的大小为2^32(在32位的x86机器上),内核将这4G字节的空间分为两部分。最高的1G字节(从虚地址0xC0000000到0xFFFFFFFF)供内核使用,称为“内核空间”。而较低的3G字节(从虚地址0x00000000到0xBFFFFFFF),供各个进程使用,称为“用户空间”。也就是说,在这4G的…

    2022年9月15日
    4
  • 常驻内存以及如何避免内存泄漏

    常驻内存以及如何避免内存泄漏

    2022年2月13日
    45
  • HttpOnly的设置[通俗易懂]

    HttpOnly的设置[通俗易懂]描述:1.会话cookie中缺少HttpOnly属性会导致攻击者可以通过程序(JS脚本、Applet等)获取到用户的cookie信息,造成用户cookie信息泄露,增加攻击者的跨站脚本攻击威胁。2.HttpOnly是微软对cookie做的扩展,该值指定cookie是否可通过客户端脚本访问。MicrosoftInternetExplorer版本6ServicePack1和更高…

    2022年6月15日
    37
  • TimSort算法相关

    TimSort算法相关今天看 Java 的 Collection sort 的源码 发现采用的是 TimSort sort 就在网上查了下 发现一个不错的文章 原链接如下 http www freebuf com vuls 62129 html nbsp nbsp 如何找出 Timsort 算法和玉兔月球车中的 Bug nbsp 0 00 背景形式化方法 FormalMethod 在我们一般人眼中是非常高大上的东西

    2025年6月26日
    3
  • oracle替换指定字符串_字符串的替换函数

    oracle替换指定字符串_字符串的替换函数REPLACE()用法:replace(原字段,“原字段旧内容“,“原字段新内容“,)例如:SELECTREPLACE(‘abcde’,’a’,NULL)ASstrFROMdual;–bcde

    2022年9月6日
    6

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号