dtueufe82643 2016-02-16 07:30
浏览 28
已采纳

每周日历减去星期日

I got this code from here: Creation of weekly calender in php

My question is, how do I make it end up to Saturday only?

    <?php
    $dt = new DateTime;
    if (isset($_GET['year']) && isset($_GET['week'])) {
        $dt->setISODate($_GET['year'], $_GET['week']);
    } else {
        $dt->setISODate($dt->format('o'), $dt->format('W'));
    }
    $year = $dt->format('o');
    $week = $dt->format('W');
?>

<center>
<a href="<?php echo $_SERVER['PHP_SELF'].'?week='.($week-1).'&year='.$year; ?>" style="padding-right: 600px">Previous Week</a> <!--Previous week-->
<a href="<?php echo $_SERVER['PHP_SELF'].'?week='.($week+1).'&year='.$year; ?>" style="padding-left: 600px">Next Week</a> <!--Next week-->
</center>

<table border="1" style="text-align: center" align="center">
    <col width="100px" />
    <col width="200px" />
    <col width="200px" />
    <col width="200px" />
    <col width="200px" />
    <col width="200px" />
    <col width="200px" />
    <tr>
        <td>Time</td>
    <?php
        do {
            echo "<td>" . $dt->format('l') . "<br>" . $dt->format('F d') . "</td>
";
            $dt->modify('+1 day');
        } while ($week == $dt->format('W'));
    ?>
  • 写回答

1条回答 默认 最新

  • drq1257 2016-02-16 14:44
    关注

    Solved by replacing this:

    do {
        echo "<td>" . $dt->format('l') . "<br>" . $dt->format('F d') . "</td>
    ";
        $dt->modify('+1 day');
    } while ($week == $dt->format('W'));
    

    to this:

    for($day=1;$day<=6;$day++){
        echo "<td>" . $dt->format('l') . "<br>" . $dt->format('F d') . "</td>
    ";
        $dt->modify('+1 day');
    }
    

    :D

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器