<?php class Date{ /** * 获取某年某月的开始结束日期 * @param int $year * @param int $month */ public function getMonthStartEnd($year, $month){ $firstday = date('Y-m-d', mktime(0, 0, 0, $month, 1,$year)); $lastday = date('Y-m-d', mktime(0, 0, 0,$month+1,1,$year)-1); $return = array( 'start'=>$firstday, 'end'=>$lastday, 'stime'=>strtotime($firstday), 'etime'=>strtotime($lastday) ); return $return; } /** * 获取某年某周的开始结束日期 * @param int $year * @param int $week 1~52 */ public function getWeekStartEnd($year,$week){ $weeks = date("W", mktime(0, 0, 0, 12, 28, $year)); if ($week > $weeks || $week <= 0) { $week = 1; } if ($week < 10) { $week = '0' . $week; } $time['stime'] = strtotime($year . 'W' . $week); $time['etime'] = strtotime('+1 week -1 day', $time['stime']); $time['start'] = date('Y-m-d',$time['stime']); $time['end'] = date('Y-m-d',$time['etime']); return $time; } }