PHP获取某年第几周德起始终止日期

来源:互联网 发布:抄板软件 编辑:程序博客网 时间:2024/04/29 18:12

防止以后忘掉,贴在这儿啦

 function GetWeekDate($week,$year)
 {
       $timestamp = mktime(0,0,0,1,1,$year);
       $dayofweek = date("w",$timestamp);
       if( $week != 1)
                $distance = ($week-1)*7-$dayofweek+1;
        $passed_seconds = $distance * 86400;
        $timestamp += $passed_seconds;  
      $firt_date_of_week = date("Ymd",$timestamp);
      if($week == 1)
                 $distance = 7-$dayofweek;
       else
        $distance = 6;
      $timestamp += $distance * 86400;
     $last_date_of_week = date("Ymd",$timestamp);
     return array($firt_date_of_week,$last_date_of_week);
 }