Home > php教程 > php手册 > body text

PHP编写普通日历,显示当天和当月的情况的代码

WBOY
Release: 2016-06-06 19:37:59
Original
2570 people have browsed it

编写普通日历,显示当天和当月的情况 无 ?php date_default_timezone_set('PRC'); $tdate = getdate(); //当前时间 $tmday = $tdate['mday']; //今天几号 $twday = $tdate['wday']; //今天星期几 $mon = $tdate['mon']; //月份 $year = $tdate['year']; //今年

编写普通日历,显示当天和当月的情况
<?php 
 date_default_timezone_set(&#39;PRC&#39;);
 $tdate = getdate(); //当前时间
 $tmday = $tdate[&#39;mday&#39;]; //今天几号
 $twday = $tdate[&#39;wday&#39;]; //今天星期几
 $mon = $tdate[&#39;mon&#39;]; //月份
 $year = $tdate[&#39;year&#39;]; //今年
 $sdate = getdate(mktime(0,0,0,$mon,1)); //本月1号
 $swday = $sdate[&#39;wday&#39;]; //本月一号星期几
 if($mon==2)
 {
	 if($year % 4==0 && $year % 100!=0 || $year %400 ==0)
		 $days = 29;
	 else 
		 $days = 28;
 }
 else if($mon == 4 || $mon == 6 || $mon == 9 || $mon == 11)
	 $days = 30;
 else
	 $days = 31;
 $edate = getdate(mktime(0,0,0,$mon,$days));//本月最后一天
 $ewday = $edate[&#39;wday&#39;]; //本月最后一天星期几
 $counts = 0; //计数器
 $html = "<table style=&#39;border: solid 1px black&#39;>";
 $html .="<tr><th colspan=&#39;6&#39;>{$year}年{$mon}月<th></tr>";
 $html .="<tr><th>星期日</th><th>星期一</th><th>星期二</th><th>星期三</th><th>星期四</th><th>星期五</th><th>星期六</th></tr>";
 $html .="<tr>";
 for($i = 0; $i < ($swday % 7);$i++)
	 $html .=&#39;<td></td>&#39;;
 while($counts != $days)
 {
	 if(($swday+$counts)%7 ==0)
         $html .="<tr><td align=&#39;center&#39; style=".($styles = (($counts+1) ==$tmday ? &#39;color:red;font-weight:bold&#39; : &#39;&#39;)).">".(++$counts).&#39;</td>&#39;;
	 else if(($swday+$counts)%7 ==6)
		 $html .="<td align=&#39;center&#39; style=".($styles = (($counts+1) ==$tmday ? &#39;color:red;font-weight:bold&#39; : &#39;&#39;)).">".(++$counts).&#39;</td></tr>&#39;;
	 else
		 $html .="<td align=&#39;center&#39; style=".($styles = (($counts+1) ==$tmday ? &#39;color:red;font-weight:bold&#39; : &#39;&#39;)).">".(++$counts).&#39;</td>&#39;;
 }
 if($ewday!=6)
	 $html .=&#39;</tr>&#39;;
 $html .=&#39;</table>&#39;;
 echo $html;
?>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!