时间:2021-07-01 10:21:17 帮助过:29人阅读
$start_time =rand(time(), time() + 50 * 24 * 60 * 60);
$needed_time = 23; //day
$work_day = 5;
$needed_week = floor($needed_time/$work_day);
$end_time = $start_time + $needed_week * 7 * 24 * 60 * 60 + $needed_time%$work_day * 24 * 60 * 60;
$end_date = date("Y-m-d", $end_time);
$start_date = date("Y-m-d", $start_time);
$end_week_day = date("w", $end_time);
$weeks = array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
echo "start date: $start_date, end date: $end_date, " . $weeks[$end_week_day] . " after ". $needed_week . " weeks.";
$start_time =rand(time(), time() + 50 * 24 * 60 * 60);
$needed_time = 23; //day
$work_day = 5;
$needed_week = floor($needed_time/$work_day);
$end_time = $start_time + $needed_week * 7 * 24 * 60 * 60 + $needed_time%$work_day * 24 * 60 * 60;
$weeks = array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
$end_week_day = date("w", $end_time);
if($end_week_day == 6
------解决思路----------------------
$end_week_day == 0)
{
$needed_week ++;
$end_time += 2 * 24 * 60 * 60;
}
$end_date = date("Y-m-d", $end_time);
$start_date = date("Y-m-d", $start_time);
$end_week_day = date("w", $end_time);
echo "start date: $start_date, end date: $end_date, " . $weeks[$end_week_day] . " after ". $needed_week . " weeks.";
$x = '2015-07-27';2015-08-03 1
$d = 6;
$t = strtotime($x);
while($d > 1) { //当天不算就 $d > 0
$t += 86400;
if(in_array(date('w', $t), array(6,0))) continue;
$d--;
}
echo date('Y-m-d w', $t);