我需要在某个截止点之后返回下一个星期日的日期。例如 - 我正在运营一个竞赛网站,截止时间是每周日晚上 10 点,因此如果用户在周日晚上 10 点之后查看该网站,则需要显示下周的日期。
目前我正在使用这个:
date('F jS', strtotime('这个星期天', strtotime(date('F jS', time()))));
这很好,但只在午夜之后工作,所以只会在周一 00:00 显示下周日的日期,而我需要在周日 22:00 显示。
非常感谢任何帮助!
最佳答案
像这样简单的东西就够了吗?
$competitionDeadline = new DateTime('this sunday 10PM');
$date = new DateTime();
if ($date->format('l') === 'Sunday' && $date->format('H') >= '22') {
// It is past 10 PM on Sunday,
// Override next competition dates here... i.e.
$competitionDeadline = new DateTime('next sunday 10PM');
}
// Wherever you are presenting the competition deadline...
$competitionDeadline->format('Y-m-d H:i:s');
关于php - 在特定时间后获取下周日的日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35289410/