php根据时间返回一周开始/结束时间
function getWeekday($time = '', $first = 1){
if (!$time) $time = time();
$sdefaultDate = date("Y-m-d", $time);
//获取当前周的第几天 周日是 0 周一到周六是 1 - 6
$w = date('w', strtotime($sdefaultDate));
//获取本周开始日期,如果$w是0,则表示周日,减去 6 天
$week_start = date('Ymd', strtotime("$sdefaultDate -" . ($w ? $w - $first : 6) . ' days'));
//本周结束日期
$week_end = date('Ymd', strtotime("$week_start +6 days"));
return array("week_start" => $week_start, "week_end" => $week_end);
}
当前页面是本站的「Google AMP」版。查看和发表评论请点击:完整版 »