当前位置:Gxlcms > PHP教程 > 请教这种计算工作时间结束的具体时间戳应该如何写

请教这种计算工作时间结束的具体时间戳应该如何写

时间:2021-07-01 10:21:17 帮助过:29人阅读

请问这种计算工作时间结束的具体时间戳 应该怎么写
起始时间是随机的日期时间戳是X
总共需要工作6天才能完成
但是上班时间只有5天/周
我想得到下周几才能完成,包括具体的时间戳,星期几

这里要如何判断周六日,把他们再每一次都隔过去呢

麻烦写个完整代码,感谢
------解决思路----------------------


$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;

$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';
$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);
2015-08-03 1

人气教程排行