实现输入一年里的第N周,求这第N周的日期范围:
// 一年的第几周
$week_num = 10;
// 哪一年
$year = 2018;
// 今年第一天
$year_one = $year.'-'.'01'.'-'.'01';
// 今年第一天是周几
$year_one_week = date("N",strtotime($year_one));
// 如果是第一周开始日期向前推几天
if($week_num==1){
$week_nums = '-'.($year_one_week-1).' day';
}else{
$week_nums = ($week_num-2).' week';
$next_week_day = 8-$year_one_week;
$year_one = date("Y-m-d",strtotime("+{$next_week_day} day",strtotime($year_one)));
}
// 开始日期是1号加求周减1周
$start_day = date("Y-m-d",strtotime("+{$week_nums}",strtotime($year_one)));
// 开始天加6天是结束天
$end_day = date("Y-m-d",strtotime("+6 day",strtotime($start_day)));
echo $year.'年的第'.$week_num.'周的开始日期为'.$start_day.'日,结束日期为'.$end_day;
效果如下: