这是我到目前为止所拥有的:
$date = date('Y-m-d h:i:s', strtotime('-7 days'));
$start = date('Y-m-d h:i:s', strtotime($date,'previous Sunday'));
输出 $start 时返回:1969-12-31 06:00:00
我究竟做错了什么?
$date
需要一个时间戳
$date = strtotime('-7 days');
$start = date('Y-m-d h:i:s', strtotime('previous Sunday',$date));
你有错误的论点:
date('Y-m-d h:i:s', strtotime('previous Sunday', $date));
编辑:此外,您制作$date
了一个格式化的字符串。它必须是时间戳,因此您的代码应如下所示:
$date = strtotime('-7 days');
$start = date('Y-m-d h:i:s', strtotime('previous Sunday', $date));
每个php 文档
date('Y-m-d h:i:s', strtotime('last Sunday', $date));
如果您的日期不是时间戳,您仍然可以使用strtotime
,例如假设您的日期已经传入并且是另一种字符串格式。
$date = '2013-11-10';
$lastsunday = date('Y-m-d',strtotime($date.' last Sunday'));
这可以节省一些时间尝试将您的日期转换为“有效”的格式