• 日历小算法:


    日历小算法:

    <?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');
  • 相关阅读:
    总结
    spring boot 使用mongodb基本操作与一些坑
    java 在循环中删除数组元素之二
    学习spring cloud 笔记
    一些名词解释
    redis--分布式锁
    微信小程序的加密与解密--java
    java 动态代理
    (收藏)CORS(跨域资源共享)
    策略模式学习笔记--在写更好的代码路上
  • 原文地址:https://www.cnblogs.com/godrain/p/4414135.html
Copyright © 2020-2023  润新知