function getWeekStartAndEnd ($year,$week=1) { header("Content-type:text/html;charset=utf-8"); date_default_timezone_set("Asia/Shanghai"); $year = (int)$year; $week = (int)$week; //按给定的年份计算本年周总数 $date = new DateTime
function getWeekStartAndEnd ($year,$week=1) { header("Content-type:text/html;charset=utf-8"); date_default_timezone_set("Asia/Shanghai"); $year = (int)$year; $week = (int)$week; //按给定的年份计算本年周总数 $date = new DateTime; $date->setISODate($year, 53); $weeks = max($date->format("W"),52); //如果给定的周数大于周总数或小于等于0 if($week>$weeks || $week<=0){ return false; } //如果周数小于10 if($week<10){ $week = '0'.$week; } //当周起止时间戳 $timestamp['start'] = strtotime($year.'W'.$week); $timestamp['end'] = strtotime('+1 week -1 day',$timestamp['start']); //当周起止日期 $timeymd['start'] = date("Y-m-d",$timestamp['start']); $timeymd['end'] = date("Y-m-d",$timestamp['end']); //返回起始时间戳 return $timestamp; //返回日期形式 //return $timeymd; }