Heim > Backend-Entwicklung > PHP-Tutorial > 请教这种计算工作时间结束的具体时间戳 应该如何写

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

WBOY
Freigeben: 2016-06-13 12:25:42
Original
955 Leute haben es durchsucht

请问这种计算工作时间结束的具体时间戳 应该怎么写
起始时间是随机的日期时间戳是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 />
Nach dem Login kopieren
Nach dem Login kopieren

------解决思路----------------------
引用:
<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 />
Nach dem Login kopieren
Nach dem Login kopieren

<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 />
Nach dem Login kopieren


------解决思路----------------------
与其费脑筋推演算式,还不如用计算机最擅长简单累加
$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);
Nach dem Login kopieren
2015-08-03 1

Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage