当前位置: 首页 > 后端技术 > PHP

PHP获取一年中的周数以及每周的开始日期和结束日期

时间:2023-03-30 05:19:14 PHP

一年有多个星期,每个星期的开始日期和结束日期参考代码1:[使用版本]$weeks||$week<=0){$week=1;}if($week<10){$week='0'.$周;//注意:一定要转换成2位数字,否则计算会出错}$timestamp['start']=strtotime($year.'W'.$week);$timestamp['end']=strtotime('+1week-1day',$timestamp['start']);echo$year.'年'。$周。'周开始时间戳:'。$时间戳['开始']。'';回声$年。'年'。$周。'周末时间戳:'。$时间戳['结束']。'';回声$年。'年'。$周。'周开始日期:'。日期(“Y-m-d”,$timestamp['开始'])。'';回声$年。'年'。$周。'周末结束日期:'。date("Y-m-d",$timestamp['end']);?>参考代码2:[尚未验证]setISODate($year,53);返回($date->格式(“W”)===“53”?53:52);}functionweekday($custom_date){$week_start=date('d-m-Y',strtotime('本周星期一',$custom_date));$week_end=date('d-m-Y',strtotime('本周周日',$custom_date));$week_array[0]=$week_start;$week_array[1]=$week_end;return$week_array;}echo'2013年的周数'.getIsoWeeksInYear(2013);$weekday=weekday(strtotime(date('d-m-Y',strtotime('5-8-2013'))));echo'10-8-2013';echo'start:'.$weekday[0];echo'end:'.$工作日[1];?>