php 算出上周第一天和最后一天,以今天为时间

2024-12-18 22:44:27
推荐回答(2个)
回答1:

$n = time() - 86400 * date('N', time());

echo date('Y-m-d', $n - 86400 * 6 );
echo ' ';
echo date('Y-m-d', $n);

回答2:

date_default_timezone_set('Asia/Shanghai');
$time = time() - 86400 * 7;
$start_time = mktime( 0,0, 0, date('m',$time) ,date('d',$time) - date('N',$time) + 1 ,date( 'Y',$time ));
$end_time = mktime( 0,0, 0, date('m',$time) ,date('d',$time) - date('N',$time) + 7 , date('Y',$time));
var_dump(date('Y-m-d',$start_time),date('Y-m-d',$end_time));
?>