如何添加[今天的日期+1天]


How to add [today's date +1 day]

我目前正在wordpress:中使用此代码

// [date]  
function displaydate(){  
return date('l, F jS, Y');  
}  
add_shortcode('date', 'displaydate');  
// end date

--

我想做的是添加另一个短代码,显示今天的日期+1天。

所以我可以写这样的东西:

'。。。报价用完[今天+1天]'

有人知道怎么做吗?

PHP中最简单的方法是使用strtotime函数。

至于你的代码,你会添加:

return date('l, F jS, Y', strtotime('+1 day'));

根据你的原始代码,一个名为"明天"的"短代码"看起来像这样:

// [tomorrow]  
function displaydate_tomorrow(){  
    return date('l, F jS, Y', strtotime('+1 day')); 
}  
add_shortcode('tomorrow', 'displaydate_tomorrow'); 
// end tomorrows date

PHP文档在日期操作方面非常全面,因此找到合适的解决方案应该很容易。这里有一个可能的解决方案:

function displaydate($plus_days) {
  return date('l, F jS, Y', strtotime('+' . $plus_days . ' day'));
}

http://uk3.php.net/manual/en/function.strtotime.php

这是我能找到的这个问题的唯一直接答案,我非常感谢您提供的答案。

我还玩了一些变量,因为我想显示一个准确的日期,当我在多伦多地区时,把天改为小时,输入-5到GMT时间,效果很好!

对于新手来说,我使用的完整代码如下:

 function displaydate(){
     return date('l, F jS, Y', strtotime('-5 hours')); 
 }
 add_shortcode('date', 'displaydate');

然后,我在我希望日期显示在我的wordpress页面上的页面上输入以下内容:

Last update of this page: [date]

并且结果是完美的。

我使用这个片段来计算简单的预计交付日期。它基于dianovich的片段,但他的(她)片段返回错误。这很好:

function displaydate( $atts ) {
    $atts = shortcode_atts( array(
        'day'   => '0'     
    ), $atts );
    $plus_days = $atts['day'];
    return date_i18n('j F Y', strtotime('+' . $plus_days . ' day'));
}
add_shortcode('delivery_date', 'displaydate');

要显示的短代码:[delivery_date day="5"]