持续完善 Pinda.cn 秒建营销活动 通过低代码 零代码的模式快速创建营销活动,欢迎使用 。

PHP获取本周的每一天的时间

1.PHP获取未来一周的时间

public function getWeek()
{
    for($i=0;$i<7;$i++)
    {
        $arr[$i]=date('Y-m-d',strtotime(date('Y-m-d').'-'.$i.'day'));
    }

    return json($arr);
}    

 

2.PHP获取本周每一天的时间

public function getDay()
{
$timestr = time(); //当前时间戳
$now_day = date('w',$timestr); //当前是周几

//获取周一
$monday_str = $timestr - ($now_day-1)*60*60*24;
$monday = date('Y-m-d', $monday_str);

//获取周日
$sunday_str = $timestr + (7-$now_day)*60*60*24;
$sunday = date('Y-m-d', $sunday_str);

for($i=0;$i<7;$i++)
{
$arr[$i]=date('Y-m-d',strtotime($monday.'+'.$i.'day'));
}
return json($arr);
// echo "星期一: $monday\n";
// echo "星期天: $sunday\n";
}

 

效果:

["2023-11-11","2023-11-12","2023-11-13","2023-11-14","2023-11-15","2023-11-16","2023-11-17"]

posted @ 2023-10-13 19:17  工具人Kim哥  阅读(330)  评论(0编辑  收藏  举报
持续完善 Pinda.cn 秒建营销活动 通过低代码 零代码的模式快速创建营销活动,欢迎使用 。