我使用以下代码显示下一个星期四的日期。
现在我遇到了以下问题:今天是星期四,但是我不想显示下周的日期,直到当天结束。怎么可能?
每个星期四下午7点至晚上10点,我们有职责。因此,我需要显示今天的日期。晚上10点后,我可以显示下周四的日期(例如30.11。)
当前代码:
$timestmp = strtotime('next thursday');
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;
if(date('l')=='星期四'){ 回声今天是星期四!惠拉!' } 别的 { $ timestmp = strtotime('下周四'); setLocale(lc_time," de_de"); $ next = strftime('%a,%d。%m。%y',$ timestmp); }
所以您今天想展示这个星期四吗?然后传递到昨天的时间戳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');