首页 > 后端开发 > php教程 > 请教这种计算工作时间结束的具体时间戳 应该如何写

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

WBOY
发布: 2016-06-13 12:25:42
原创
951 人浏览过

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

------解决思路----------------------
引用:
<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 />
登录后复制
登录后复制

<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 />
登录后复制


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

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板