用strtotime()和date()函数算出2019年9月的周日日期

倾然丶 夕夏残阳落幕 提交于 2019-11-30 04:48:07
  • strtotime
<?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

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!