由于老外的星期都是从周日开始,中国习惯从周一开始
结果直接用strtotime("last monday") 就会的出错误的结果
为了解决这个问题。代码如下
$date = date("Y-m-d"); //当前日期
$first=1; //$first =1 表示每周星期一为开始时间 0表示每周日为开始时间
$w = date("w", strtotime($date)); //获取当前周的第几天 周日是 0 周一 到周六是 1 -6
$d = $w ? $w - $first : 6; //如果是周日 -6天
$now_start = date("Y-m-d", strtotime("$date -".$d." days")); //本周开始时间
$now_end = date("Y-m-d", strtotime("$now_start +6 days")); //本周结束时间
$last_start = date('Y-m-d',strtotime("$now_start - 7 days")); //上周开始时间
$last_end = date('Y-m-d',strtotime("$now_start - 1 days")); //上周结束时间