PHP时间表日发行

PHP时间表日发行,php,Php,我只包括了一些我的时间表脚本(处理日期的部分) 我注意到我的时间表一直运行良好,直到月底(每天变成周四),因此我回到了脚本中,我相信我的时间表不知道何时检测是否是新月份,因此它继续像计数器31、32、33(月日)一样工作这是不存在的,这就是为什么它每天都给我一个星期四,说这一年是1970年 时间表显示从今天开始的5天-因此它将显示今天和其他4天,例如周五、周六、周日和周一 我的代码如下: <?php } $timein = time(); $d7 =

我只包括了一些我的时间表脚本(处理日期的部分)

我注意到我的时间表一直运行良好,直到月底(每天变成周四),因此我回到了脚本中,我相信我的时间表不知道何时检测是否是新月份,因此它继续像计数器31、32、33(月日)一样工作这是不存在的,这就是为什么它每天都给我一个星期四,说这一年是1970年

时间表显示从今天开始的5天-因此它将显示今天和其他4天,例如周五、周六、周日和周一

我的代码如下:

       <?php
    }
    $timein = time();
    $d7 = date("H", $timein);
    $d6 = ($d7 +1) - 4;
    $d1 = date("d", $timein);

    $d2 = date("F", $timein);   
    $d3 = date("Y", $timein);
    $d4 = "$d2 $d3";
    $d5 = $d1 + 4;
    for( $i = $d1; $i <= $d5; $i++ ) {
    $day = strtotime( "{$i} {$d4}" );
    $day = date( "d/m/Y", $day );

    ?>
    <table border="0" cellspacing="0" cellpadding="0" width="20%" style="float: left;">
    <tr><td>
        <div class="square title" style="padding: 3px; -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; width: 92%; text-align: center; bottom: 5px; margin-bottom: 5px; cursor: pointer; background: #79CDCD;">

            <strong><?php echo $day; ?></strong>

        </div>
</td></tr>
</table>
<? } ?>


有没有解决方案或更简单的方法来编写这种脚本


提前感谢您的帮助

您只需将86400秒添加到
$timein
以增加一天的时间,如何?

您可以使用
strotime
获取今天午夜的值,并在for循环中添加
$i

<?php

    for( $i = 0; $i < 5; $i++ ) {
        $day = strtotime( "today + $i days" );
        $day = date( "d/m/Y", $day );

        ?>
        <table border="0" cellspacing="0" cellpadding="0" width="20%" style="float: left;">
            <tr>
                <td>
                    <div class="square title" style="padding: 3px; -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; width: 92%; text-align: center; bottom: 5px; margin-bottom: 5px; cursor: pointer; background: #79CDCD;">
                        <strong><?php echo $day; ?></strong>
                    </div>
                </td>
            </tr>
        </table>
<? } ?>



正如njk建议的那样,您也可以通过增加86400秒的倍数来实现

<?php

for( $i = 0; $i < 5; $i++ ) {
    $day = time() + ($i * 86400);
    $day = date( "d/m/Y", $day );

    ?>
    <table border="0" cellspacing="0" cellpadding="0" width="20%" style="float: left;">
        <tr>
            <td>
                <div class="square title" style="padding: 3px; -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; width: 92%; text-align: center; bottom: 5px; margin-bottom: 5px; cursor: pointer; background: #79CDCD;">
                    <strong><?php echo $day; ?></strong>
                </div>
            </td>
        </tr>
    </table>
<? } ?>



您的代码似乎很难理解。这通常不是个好兆头。在处理日期时,我通常更喜欢面向对象的方法:

$date = new DateTime();

for ($i = 0; $i <= 4; $i++) {
    ?>
    <table border="0" cellspacing="0" cellpadding="0" width="20%" style="float: left;">
    <tr><td>
        <div class="square title" style="padding: 3px; -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; width: 92%; text-align: center; bottom: 5px; margin-bottom: 5px; cursor: pointer; background: #79CDCD;">

            <strong><?php echo $date->format('d/m/Y'); ?></strong>

        </div>
    </td></tr>
    </table>
    <?php
    $date->add(new DateInterval('P10D'));
}
$date=new DateTime();
对于($i=0;$i)


你忘了夏令时。