[英]PHP mktime include Day of the Week and Month/Day
I have a PHP page that shows information based on the current day of the week and also allows for the ability to +1 or -1 from the current day based on _GET passed in the URL. 我有一个PHP页面,该页面显示基于一周中当前日期的信息,并且还允许基于URL中传递的_GET从当前日期开始+1或-1。 This is working correctly as you see here where the H2 displays the Day of the week.
正如您在此处看到的那样,H2显示星期几的地方,这可以正常工作。 I also need to display the Month/Day
我还需要显示月份/日期
<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>
I tried adding the echo $display_day but it is not showing anything like this? 我尝试添加回显$ display_day,但未显示任何类似信息? What am I missing?
我想念什么?
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>
You could use the DateTime object. 您可以使用DateTime对象。
So you would be able to do this: 这样您就可以执行以下操作:
$today = new DateTime('today');
$yesterday = $today->modify('-1 day');
$tomorrow = $today->modify('+1 day');
Then you just need to format the date by doing this: 然后,您只需执行以下操作即可格式化日期:
$tomorrow_date = $tomorrow->format('l, F d');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.