簡體   English   中英

顯示下周四的日期

[英]Show date of next thursday

我使用以下代碼顯示每個下周四的日期。

現在,我遇到了以下問題:今天是星期四,但是直到今天結束,我都不想顯示下一周的日期。 那怎么可能?

每個星期四晚上7點至晚上10點都有工作。 因此,我需要顯示例如今天的日期。 晚上10點之后,我可以顯示下一個星期四的日期(例如30.11。)

當前代碼:

 $timestmp = strtotime('next thursday');
 setlocale(LC_TIME, "de_DE");
 $next = strftime('%A, %d.%m.%Y', $timestmp); 

if(date('l')=='星期四'){echo'今天是星期四! 哇! } else {$ timestmp = strtotime('下周四'); setlocale(LC_TIME,“ de_DE”); $ next = strftime('%A,%d。%m。%Y',$ timestmp); }

您可以使用簡單的if condition來檢查今天是否是星期四,並打印今天的日期。 否則,下周四打印

setlocale(LC_TIME, "de_DE");

if (date('l') == 'Thursday') {
    $thu = strftime('%A, %d.%m.%Y');
} else {
    $timestmp = strtotime('next thursday');
    $thu = strftime('%A, %d.%m.%Y', $timestmp);
}

echo $thu;

所以你想在今天星期四演出嗎? 然后傳遞到strtotime,即昨天的時間戳。 像那樣

 $timestmp = strtotime('next thursday', strtotime('-1 day'));

然后它將從昨天(今天)的下一個星期四開始尋找。

以下代碼在下周日(星期日,星期一,星期二或星期三)進行抓取。 如果是星期五或星期六,它將抓住最后一個星期四。 如果今天是星期四,它將抓住當前的一天。

$now = new DateTime();
if ($now->format('w') < 4) {
    $now->modify('next thursday')
} elseif ($now->format('w') > 4) {
    $now->modify('last thursday')
}

echo $now->format('Y-m-d');

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM