【发布时间】:2015-03-02 22:58:09
【问题描述】:
即:
如果现在低于本周周五 10:00,则创建包含前一周周六的数组,然后是本周周日、周一、周二、周三和周五。
如果 now 超过本周星期五 10:00,则将之前的数组替换为包含本周星期六的另一个数组,然后是星期日星期一星期二星期三和下周星期五。
我无法用脚本表达这种情况的逻辑。
谢谢
在阅读了很多很多帖子后,我发现这是行不通的
$current_time = strtotime('now');
$week_start_day = "friday";
$start_time = "10:00";
if ($current_time <= strtotime('$week_start_day this week $start_time')) {
$day_1 = date('d/m/Y', strtotime('previous week friday', strtotime(date('d-m-Y'))));
$day_2 = date('d/m/Y', strtotime('previous week saturday ', strtotime(date('d-m-Y'))));
$day_3 = date('d/m/Y', strtotime('previous week sunday ', strtotime(date('d-m-Y'))));
$day_4 = date('d/m/Y', strtotime('previous week monday', strtotime(date('d-m-Y'))));
$day_5 = date('d/m/Y', strtotime('previous week tuesday', strtotime(date('d-m-Y'))));
$day_6 = date('d/m/Y', strtotime('this week wednesday ', strtotime(date('d-m-Y'))));
$day_7 = date('d/m/Y', strtotime('this week thursday ', strtotime(date('d-m-Y'))));
}
else{
$day_1 = date('d/m/Y', strtotime('this week saturday ', strtotime(date('d-m-Y'))));
$day_2 = date('d/m/Y', strtotime('this week sunday', strtotime(date('d-m-Y'))));
$day_3 = date('d/m/Y', strtotime('this week monday', strtotime(date('d-m-Y'))));
$day_4 = date('d/m/Y', strtotime('this week tuesday ', strtotime(date('d-m-Y'))));
$day_5 = date('d/m/Y', strtotime('this week wednesday ', strtotime(date('d-m-Y'))));
$day_6 = date('d/m/Y', strtotime('this week thursday ', strtotime(date('d-m-Y'))));
$day_7 = date('d/m/Y', strtotime('this week friday ', strtotime(date('d-m-Y'))));
}
echo "
$day_1 <br>
$day_2 <br>
$day_3 <br>
$day_4 <br>
$day_5 <br>
$day_6 <br>
$day_7 <br>
";
【问题讨论】:
-
您的脚本有什么问题?好吧,你在这里一遍又一遍地做同样的事情。您不能只设置开始日期并使用
+1 day其余 6 个吗? -
从今天起我只需要 7 天。但情况更为复杂。如果你帮我解决,你必须了解情况