本文目录一览:
php求一段时间内各周的起始时间和结束时间
function getTimeList($startTime, $endTime, $isWeek=true) {
$result = array();
if(!($st = strtotime($startTime)) || !($et = strtotime($endTime))) return false;
$day = 86400; //一天24*60*60
$sDate = getdate($st);
if($isWeek) {
$result['weekly'] = array();
$nextTime = (6 - $sDate['wday']) * $day + $st;
$currentTime = $st;
while($nextTime $et) {
$result['weekly'][] = array('weekStart' = gmdate('Y-m-d', $currentTime), 'weekEnd' = gmdate('Y-m-d', $nextTime));-php月末时间
$currentTime = $nextTime + 86400;
$nextTime = $nextTime + 604800;//7天*24小时*60分*60秒
}
$result['weekly'][] = array('weekStart' = gmdate('Y-m-d', $currentTime), 'weekEnd' = $endTime);
} else {
$result['monthly'] = array();
$currentMonth = $st;
$m = $sDate['mon'];
$year = $sDate['year'];
while($lastMonth $et) {
if($m == 12) {
$m = 1;
$year = $year + 1;
} else $m++;
$firstDate = strtotime($year."-".$m."-01"); //下月初时间截
$lastMonth = $firstDate - $day;//得到本月末时间截
if($lastMonth $et) $lastMonth = $et;
$result['monthly'][] = array('monthStart' = gmdate('Y-m-d', $currentMonth), 'monthEnd' = gmdate('Y-m-d', $lastMonth));-php月末时间
$currentMonth = $firstDate;
}
}
return $result;
}
调用:
$w = getTimeList('2013-05-02', '2013-08-06');
print_r($w);
echo 'p/';
$m = getTimeList('2013-05-02', '2014-03-06', false);
print_r($m);
测试OK,你看看是不是你想要的吧
php如何求上一个月月初至月末?
由于php内置时间函数 strtotime 在求上个月这个功能上存在bug,所以放弃不用了……
上个自己写的临时用的,楼主看看:
$thismonth = date('m');
$thisyear = date('Y');
if($thismonth==1) {
$lastmonth = 12;
$lastyear = $thisyear-1;
} else {
$lastmonth = $thismonth - 1;
$lastyear = $thisyear;
}
$lastStartDay = $lastyear.'-'.$lastmonth.'-1';
$lastEndDay = $lastyear.'-'.$lastmonth.'-'.date('t',strtotime($lastStartDay));
echo 'lastStartDay = '.$lastStartDay;
echo 'br/';
echo 'lastEndDay = '.$lastEndDay;
php 加载的时候有没有办法设置默认时间加上半年,显示!
从语法上来看你有点象thinkphp
{$vo.collect_time+15552000|mydate='Y-m-d H:i:s',###}
或者直接写源码
phpecho date("Y-m-d H:i:s", strtotime("+6 months")); /php