PHP获取第几周的开始和结束时间

Php  
  1. protected function weekday($year,$week=1)
  2. {
  3. $year_start = mktime(0,0,0,1,1,$year);
  4. $year_end = mktime(0,0,0,12,31,$year);
  5. // 判断第一天是否为第一周的开始
  6. if (intval(date('W',$year_start))===1){
  7. $start = $year_start;//把第一天做为第一周的开始
  8. }else{
  9. $week++;
  10. $start = strtotime('+1 monday',$year_start);//把第一个周一作为开始
  11. }
  12. // 第几周的开始时间
  13. if ($week===1){
  14. $weekday['start'] = $start;
  15. }else{
  16. $weekday['start'] = strtotime('+'.($week-0).' monday',$start);
  17. }
  18. // 第几周的结束时间
  19. $weekday['end'] = strtotime('+1 sunday',$weekday['start']);
  20. if (date('Y',$weekday['end'])!=$year){
  21. $weekday['end'] = $year_end;
  22. }
  23. $weekday['start'] = date('Y-m-d',$weekday['start']);
  24. $weekday['end'] = date('Y-m-d',$weekday['end']);
  25. return $weekday;
  26. }


评论 1

发表评论


1

12

123

1年前 ·

Top