<?php $firstsunday = strtotime(date(‘Y-m-01‘)); $thisy = intval(date(‘m‘)); $diffdays=0; $count = 0; if (date(‘w‘,strtotime(date(‘Y-m-01‘)))!=0) { $diffdays=7-date(‘w‘,strtotime(date(‘Y-m-01‘))); } else{ $count++; } $startdate =strtotime(date(‘Y-m-01‘)."+".$diffdays."day"); while (True) { if ($thisy!=intval(date(‘m‘,$startdate))) { break; } echo date(‘Y-m-d‘,$startdate)."\n"; $startdate = strtotime(date(‘Y-m-d‘,strtotime(date(‘Y-m-d‘,$startdate)."+7 day"))); // }
结果
2019-09-01 2019-09-08 2019-09-15 2019-09-22 2019-09-29
用strtotime()和date()函数算出2019年9月的周日日期
原文:https://www.cnblogs.com/saintdingspage/p/11561246.html