如何创建从周三到周五的 7 天数组以在周五上午 10 点更改
How to create array of seven days from Wednesday until Friday to change on Friday at 10 am
即:
如果本周周五小于10:00,创建数组包含前一周的周六,接下来是本周的周日、周一、周二、周三和周五。
如果现在是本周周五多于10:00,则将之前的数组替换为另一个包含本周周六的数组,然后是周日周一周二周三和下周周五。
我无法用脚本表达这种情况的逻辑。
谢谢
看了很多很多post我觉得这个不行
$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>
";
如果我对你的理解正确,这就是你想要的,还没有很好地测试它,所以可能有错误,但这是我的想法。
$fri=strtotime(" Friday this week + 4 hours ");// 10:00 GMT
$now=time();
$week=array();
if($now<=$fri)
{
$day = "last Saturday";
}
else
{
$day = "next Saturday";
}
for($i=0;$i<7;$i++)
{
$week[] = date("d/m/Y", strtotime($day." +".$i." day"));
}
foreach($week as $day)
{
echo $day;
}
即:
如果本周周五小于10:00,创建数组包含前一周的周六,接下来是本周的周日、周一、周二、周三和周五。
如果现在是本周周五多于10:00,则将之前的数组替换为另一个包含本周周六的数组,然后是周日周一周二周三和下周周五。
我无法用脚本表达这种情况的逻辑。
谢谢
看了很多很多post我觉得这个不行
$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>
";
如果我对你的理解正确,这就是你想要的,还没有很好地测试它,所以可能有错误,但这是我的想法。
$fri=strtotime(" Friday this week + 4 hours ");// 10:00 GMT
$now=time();
$week=array();
if($now<=$fri)
{
$day = "last Saturday";
}
else
{
$day = "next Saturday";
}
for($i=0;$i<7;$i++)
{
$week[] = date("d/m/Y", strtotime($day." +".$i." day"));
}
foreach($week as $day)
{
echo $day;
}