在php中显示基于当前日期的日期

时间:2015-10-12 09:42:28

标签: php date

我使用以下代码,根据当天显示日期,即如果今天是星期一或星期二,则应显示下一个星期三的日期,如果有任何其他日期,则应显示下一个星期一日期。

以下是代码:

<?php
    $date = str_replace("/", "-", $date);
    $nextWed = date("l jS F, Y",strtotime('next wednesday'));
    $nextMon = date("l jS F, Y",strtotime('next monday'));

if(date('D', $timestamp) === 'Mon' or date('D', $timestamp) === 'Tue' ){ 

echo '<div class="time-note">Order your box before Tuesday 11.59pm and get it delivered on '.$nextWed .'</div>';}
else {
    echo '<div class="time-note">Order your box before Sunday 11.59pm and get it delivered on '.$nextMon.'</div>';}?>

如果我今天看到输出,它仍然回应Order your box before Sunday 11.59pm and get it delivered on Monday 19th October 2015。而它应该说Order your box before Tuesday 11.59pm and get it delivered on Monday 14th October 2015

2 个答案:

答案 0 :(得分:1)

您唯一缺少的是$timestamp

$timestamp = time();

下直接添加此行$nextMon = date("l jS F, Y",strtotime('next monday'));

快乐的编码!

答案 1 :(得分:0)

更改此行

if(date('D') === 'Mon' or date('D') === 'Tue' )