zoukankan      html  css  js  c++  java
  • 时间函数实现万年历

    <?php
    $time=time();

    //计算当前年
    $year=$_GET['y']?$_GET['y']:date('Y',$time);

    //计算当前月
    $month=$_GET['m']?$_GET['m']:date('m',$time);

    //当前月总计多少天?
    $days=date('t',strtotime("{$year}-{$month}-1"));

    //当前月的第一天是周几?
    $week=date('w',strtotime("{$year}-{$month}-1"));

    //计算万年历格中第一天的数字
    $first=1-$week;

    //上一月和上一年
    $prevMonth=$month-1;
    $prevYear=$year;
    if($prevMonth<1){
    $prevMonth=12;
    $prevYear=$year-1;
    }

    //下一月和下一年
    $nextMonth=$month+1;
    $nextYear=$year;
    if($nextMonth>12){
    $nextMonth=1;
    $nextYear=$year+1;
    }

    ?>
    <!doctype html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>index</title>
    <style>
    *{
    font-family: 微软雅黑;
    }

    a{
    text-decoration: none;
    color:#00f;
    }
    </style>
    </head>
    <body>
    <center>
    <?php
    echo "<h2>万年历-{$year}年{$month}月</h2>";
    ?>

    <table width='700px' border='1px' cellspacing='0'>
    <tr>
    <th>周日</th>
    <th>周一</th>
    <th>周二</th>
    <th>周三</th>
    <th>周四</th>
    <th>周五</th>
    <th>周六</th>
    </tr>
    <?php
    //布局万年历的表格
    for($i=$first;$i<=$days;){
    echo '<tr>';
    for($j=0;$j<7;$j++){
    if($i<=$days && $i>=1){
    echo "<td>{$i}</td>";
    }else{
    echo '<td>&nbsp;</td>';
    }
    $i++;
    }
    echo '</tr>';
    }
    ?>
    </table>

    <h3>
    <a href="index.php?y=<?php echo $prevYear?>&m=<?php echo $prevMonth ?>">上一月</a> |
    <a href="index.php?y=<?php echo $nextYear?>&m=<?php echo $nextMonth ?>">下一月</a>
    </h3>
    </center>
    </body>
    </html>

    勤学似春起之苗,不见其增,日有所长; 辍学如磨刀之石,不见其损,日所有亏!
  • 相关阅读:
    记一次 产品提的需求 (声音、振动)
    vue.config.js publicPath "./" npm run build无效的原因
    js 去掉字符串str中,连续重复的地方
    微信小程序map地图画圆圈效果
    2019年计划
    centos 7 nginx 远程无法访问的原因
    Eclipse配置关联Tomcat并运行项目
    .net连接mysql
    python xml.dom模块解析xml
    气象城市ID列表
  • 原文地址:https://www.cnblogs.com/qiaozhiming123/p/12888941.html
Copyright © 2011-2022 走看看