我有一个PHP页面,它显示基于当前星期几的信息,并且还允许基于URL中传递的_GET从当天开始+1或-1的能力。正如您在此处看到的那样,H2显示星期几。我还需要显示月/日
<legend>
<h2>
<?php
if (array_key_exists('day', $_GET)) {
$display_day = mktime(0, 0, 0, date("m") , date("d") + $add_day, date("Y"));
$today = date('N', $display_day);
if( $today == 7) { ?>
Sunday's
<?php } elseif( $today == 1 ) { ?>
Monday's
<?php } elseif( $today == 2 ) { ?>
Tuesday's
<?php } elseif($today == 3 ) { ?>
Wednesday's
<?php } elseif( $today == 4 ) { ?>
Thursday's
<?php } elseif( $today == 5 ) { ?>
Friday's
<?php } elseif( $today == 6 ) { ?>
Saturday's
<?php } ?> Employee Schedule</h2>
</legend>
我尝试添加echo $ display_day,但它没有显示这样的内容?我错过了什么?
if( $today == 7) { ?>
Sunday's <?php echo $display_day; ?>
<?php } elseif( $today == 1 ) { ?>
Monday's <?php echo $display_day; ?>
<?php } elseif( $today == 2 ) { ?>
Tuesday's <?php echo $display_day; ?>
<?php } elseif($today == 3 ) { ?>
Wednesday's <?php echo $display_day; ?>
<?php } elseif( $today == 4 ) { ?>
Thursday's <?php echo $display_day; ?>
<?php } elseif( $today == 5 ) { ?>
Friday's <?php echo $display_day; ?>
<?php } elseif( $today == 6 ) { ?>
Saturday's <?php echo $display_day; ?>
<?php } ?> Employee Schedule</h2>
答案 0 :(得分:1)
您可以使用DateTime对象。
所以你可以这样做:
$today = new DateTime('today');
$yesterday = $today->modify('-1 day');
$tomorrow = $today->modify('+1 day');
然后你只需要通过这样做来格式化日期:
$tomorrow_date = $tomorrow->format('l, F d');