zoukankan      html  css  js  c++  java
  • 日历小算法:

    日历小算法:

    <?php
    
    echo "<table align='center' border='1'>";
    
    echo "<th style='background-color:green;'>日</th>";
    echo "<th style='background-color:green;'>一</th>";
    echo "<th style='background-color:green;'>二</th>";
    echo "<th style='background-color:green;'>三</th>";
    echo "<th style='background-color:green;'>四</th>";
    echo "<th style='background-color:green;'>五</th>";
    echo "<th style='background-color:green;'>六</th>";
    
    $year = isset($_GET['year']) ? $_GET['year'] : date('Y');
    $month = isset($_GET['month']) ? $_GET['month'] : date('m');
    $day = isset($_GET['day']) ? $_GET['day'] : date('d');
    
    $startWeek = date('w', mktime(0,0,0,$month,1,$year)); // 当月1号是星期中的第几天 param:hour minute second month day year
    //w 星期中的第几天
    
    echo "今天是$year 年-$month 月-$day 日 ";
    
    $days = date('t', mktime(0,0,0,$month,1,$year)); // 当月有多少天
    
    echo "<tr>";
    for ($i=0; $i<$startWeek; $i++) {
    echo "<td></td>"; //补几个空位
    }
    
    
    for ($j=1; $j<=$days; $j++) {
    $i++;
    
    if ($day == $j) {
    echo "<td style='background-color:red;'>$j</td>";
    } else {
    echo "<td>$j</td>";
    }
    if ($i%7 == 0) {
    echo "</tr><tr>"; //够7个换行
    }
    
    }
    
    while($i%7 != 0) {
    echo "<td></td>"; //最后补空格
    $i++;
    }
    
    echo "<tr/>";
    echo "</table>";
    
    header('content-type:text/html;charset=utf-8');
  • 相关阅读:
    IE6绿色版下载
    bcb 取相对路经
    MyEclipse 工具
    Flex与.NET互操作(一):基于Socket的网络连接
    兼容DC
    Flex与.NET互操作(二):基于WebService的数据访问(上)
    虚函数PostNcDestroy功能
    VC++多线程编程
    POJ 1222 extended lights out 高斯消元 板子题
    hihocoder 2015 北京区域赛 A Xiongnu's Land
  • 原文地址:https://www.cnblogs.com/godrain/p/4414135.html
Copyright © 2011-2022 走看看