Rumah > pembangunan bahagian belakang > tutorial php > 请教这种计算工作时间结束的具体时间戳 应该如何写

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

WBOY
Lepaskan: 2016-06-13 12:25:42
asal
950 orang telah melayarinya

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

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

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

<br /><?php<br /><br />$start_time =rand(time(), time() + 50 * 24 * 60 * 60);<br /><br />$needed_time = 23;   //day<br /><br />$work_day = 5;<br /><br />$needed_week = floor($needed_time/$work_day);<br /><br />$end_time = $start_time + $needed_week * 7 * 24 * 60 * 60 + $needed_time%$work_day * 24 * 60 * 60;<br /><br />$end_date = date("Y-m-d", $end_time);<br /><br />$start_date = date("Y-m-d", $start_time);<br /><br />$end_week_day = date("w", $end_time);<br /><br />$weeks = array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");<br /><br />echo "start date: $start_date, end date: $end_date, " . $weeks[$end_week_day] . " after ". $needed_week . " weeks.";<br /><br />
Salin selepas log masuk
Salin selepas log masuk

------解决思路----------------------
引用:
<br /><?php<br /><br />$start_time =rand(time(), time() + 50 * 24 * 60 * 60);<br /><br />$needed_time = 23;   //day<br /><br />$work_day = 5;<br /><br />$needed_week = floor($needed_time/$work_day);<br /><br />$end_time = $start_time + $needed_week * 7 * 24 * 60 * 60 + $needed_time%$work_day * 24 * 60 * 60;<br /><br />$end_date = date("Y-m-d", $end_time);<br /><br />$start_date = date("Y-m-d", $start_time);<br /><br />$end_week_day = date("w", $end_time);<br /><br />$weeks = array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");<br /><br />echo "start date: $start_date, end date: $end_date, " . $weeks[$end_week_day] . " after ". $needed_week . " weeks.";<br /><br />
Salin selepas log masuk
Salin selepas log masuk

<br /><?php<br /><br />$start_time =rand(time(), time() + 50 * 24 * 60 * 60);<br /><br />$needed_time = 23;   //day<br /><br />$work_day = 5;<br /><br />$needed_week = floor($needed_time/$work_day);<br /><br />$end_time = $start_time + $needed_week * 7 * 24 * 60 * 60 + $needed_time%$work_day * 24 * 60 * 60;<br /><br /><br />$weeks = array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");<br /><br />$end_week_day = date("w", $end_time);<br /><br />if($end_week_day == 6 <br><font color='#FF8000'>------解决思路----------------------</font><br> $end_week_day == 0)<br />{<br />	$needed_week ++;<br />	$end_time += 2 * 24 * 60 * 60;<br />}<br />$end_date = date("Y-m-d", $end_time);<br /><br />$start_date = date("Y-m-d", $start_time);<br /><br />$end_week_day = date("w", $end_time);<br /><br /><br />echo "start date: $start_date, end date: $end_date, " . $weeks[$end_week_day] . " after ". $needed_week . " weeks.";<br /><br />
Salin selepas log masuk


------解决思路----------------------
与其费脑筋推演算式,还不如用计算机最擅长简单累加
$x = '2015-07-27';<br />$d = 6;<br /><br />$t = strtotime($x);<br />while($d > 1) { //当天不算就 $d > 0<br />  $t += 86400;<br />  if(in_array(date('w', $t), array(6,0))) continue;<br />  $d--;<br />}<br />echo date('Y-m-d w', $t);
Salin selepas log masuk
2015-08-03 1

Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan