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>

    勤学似春起之苗,不见其增,日有所长; 辍学如磨刀之石,不见其损,日所有亏!
  • 相关阅读:
    数学趣题——汉诺塔
    数学趣题——选美比赛
    数学趣题——计算组合数
    (结构型模式)Proxy——代理模式
    SHELL脚本的基础知识2——使用结构化命令
    数学趣题——寻找假币
    Cocoa使用自定义对话框的方法
    回调函数
    ObjectiveC 内存管理(转)
    mac 密码输入框控制——只能输入数字和字母,禁止特殊字符的输入
  • 原文地址:https://www.cnblogs.com/qiaozhiming123/p/12888941.html
Copyright © 2011-2022 走看看