<!-- lang: php --> php獲取當前時間以後第N個天然月最後一天的日期 <?php function get_Month($num){ //獲取當前的時間 $firstdate = date('Y-m-d'); $start=intval(date("m",strtotime($firstdate))); for($i=0;$i<$num;$i++){ if(($start+$i)>12){ $result_day = date("Y-".(($start+$i)-12)."-01",strtotime("+1 year")); }else{ $result_day = date("Y-".($start+$i)."-01",strtotime($firstdate)); } $day = date("t",strtotime($result_day)); $result_day = date("Y-m-d",(strtotime($result_day)+($day-1)*24*3600)); } return $result_day; } /** * 功能:得到某個時間段內,全部的天然月 * @param string $date * return array Array */ function getMonth(array $data){ $firstdate = $data[0]; $lastdate = $data[1]; $start=intval(date("m",strtotime($firstdate))); $end=intval(date("m",strtotime($lastdate))); for($i=$start;$i<=$end;$i++){ $firstday = date("Y-".$i."-01",strtotime($firstdate)); $lastday = date("Y-m-d",strtotime("$firstday +1 month -1 day")); $result[]=array('firstday' => $i == $start?$firstdate:$firstday,'lastday'=> $i == $end?$lastdate:$lastday); } return $result; } <!-- lang: php --> //獲取當前日期後的第n個月份 function getOneMonth($sign = 0){ $tmp_date=date("Ym"); //切割出年份 $tmp_year=substr($tmp_date,0,4); //切割出月份 $tmp_mon =substr($tmp_date,4,2); $tmp_nextmonth=mktime(0,0,0,$tmp_mon+$sign,1,$tmp_year); return date('Y-m',$tmp_nextmonth); }