[英]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”的“簡碼”如下所示:
// [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'));
}
這是我能找到的對這個問題的唯一直接答案,非常感謝您提供答案。
我還使用了變量,因為我想顯示准確的日期,並在多倫多地區將天更改為小時並輸入 -5 到格林威治標准時間,效果非常好!
對於新手,我使用的完整代碼如下:
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"]
謝謝,我用過
function displaydate(){ return date('l, F jS, Y', strtotime('+ 14 days'));
} add_shortcode('date', 'displaydate');
這很好用,除了文本是英語而網站語言設置為荷蘭語
我怎么能改變語言? 我嘗試了一些我發現的東西並立即使網站崩潰......
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.