- 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;
- //Calculate the total number of weeks in this year based on the given year
- $date = new DateTime;
- $date->setISODate($year, 53);
- $weeks = max($date->format("W"),52);
- //If the given week number is greater than the total number of weeks or less than or equal to 0
- if($week>$weeks || $week< =0){
- return false;
- }
- //If the number of weeks is less than 10
- if($week<10){
- $week = '0'.$week;
- }
- //The start and end timestamps of the current week
- $ timestamp['start'] = strtotime($year.'W'.$week);
- $timestamp['end'] = strtotime('+1 week -1 day',$timestamp['start']);
- //Start and end dates of the current week
- $timeymd['start'] = date("Y-m-d",$timestamp['start']);
- $timeymd['end'] = date("Y-m-d",$timestamp['end ']);
- //Return the starting timestamp
- return $timestamp;
- //Return the date format
- //return $timeymd;
- }
Copy code
|
Optional, one week, how many