非常全面的php日期时间运算汇总(2)

$tomorrow = date('Y-m-d',mktime (0,0,0,date("m"),date("d")+1,date("Y"))); $nextmonth = date('Y-m',mktime (0,0,0,date("m")+1,date("d")+1,date("Y"))); $nextyear = date('Y',mktime (0,0,0,date("m"),date("d"),date("Y")+1)); echo $tomorrow.'<br/>'; echo $nextmonth.'<br/>'; echo $nextyear.'<br/>';

第四种情况:工作时间(刨除假日) 

<? $startDate="2001-12-12"; $endDate="2002-11-1"; $holidayArr=array("05-01","05-02","10-01","10-01","10-02","10-03","10-04","10-05","01-26","01-27","01-28","01-29"); //假期日期数组,比方国庆,五一,春节等 $endWeek=2; //周末是否双休.双休为2,仅仅星期天休息为1,没有休息为0 $beginUX=strtotime($startDate); $endUX=strtotime($endDate); for($n=$beginUX;$n<=$endUX;$n=$n+86400){ $week=date("w",$n); $MonDay=date("m-d",$n); if($endWeek){//去处周末休息 if($endWeek==2){ if($week==0||$week==6) continue; } if($endWeek==1){ if($week==0) continue; } } if(in_array($MonDay,$holidayArr)) continue; $totalHour+=10;//每天工作10小时 } echo "开始日期:$startDate<BR>"; echo "结束日期:$endDate<BR>"; echo "共花了".$totalHour."小时"; ?>


 第五种情况:给出秒算小时

<?php function transform($sec){ $output = ''; $hours = floor($sec / 3600); $remainSeconds = $sec % 3600; $minutes = floor($remainSeconds / 60); $seconds = $sec - $hours * 3600 - $minutes * 60; if($sec >= 3600){ $output .= $hours.' h / '; $output .= $minutes.' m / '; } if($sec >= 60 && $sec < 3600){ $output .= $minutes.' m / '; } return $output .= $seconds.' s '; } echo transform(3231803); ?>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/a5ac453fa85ab3f4f03c779bfd23aa89.html