使用date()函数:PHP: date - Manual
w | 星期中的第几天,数字表示 | 0 (表示星期天)到 6 (表示星期六) |
$time = time(); // 可设定日期$week_day_num = date('w', $time);if ($week_day_num == 0) { // 当前是周日的情况 $sdate = date('Y-m-d', strtotime("-6 day", $time)); $edate = date('Y-m-d', $time);} else { $sdate = date('Y-m-d', strtotime("-" . ($week_day_num - 1) . " day", $time)); $edate = date('Y-m-d', strtotime("+" . (7 - $week_day_num) . " day", $time));}
$sdate:周一日期;$edate:周日日期
来源地址:https://blog.csdn.net/liruxing1715/article/details/126778893