每周日历减去星期日

时间:2016-02-16 07:30:36

标签: php html calendar

我从这里得到了这段代码:Creation of weekly calender in php

我的问题是,我怎么才能让它结束到星期六?

    <?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>\n";
            $dt->modify('+1 day');
        } while ($week == $dt->format('W'));
    ?>

1 个答案:

答案 0 :(得分:0)

通过替换此解决:

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

到此:

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

:d