以下是我创建的用于将星期日作为一周的开始日的函数,
function getCurrentIntervalOfWeek($liveratetime) {
// get start of each week.
$dayofweek = date('w', $liveratetime);
$getdate = date('Y-m-d', $liveratetime);
$createstart = strtotime('last Sunday', $getdate);
$weekstart = ($dayofweek == 0) ? $liveratetime : $createstart;
// get the current time interval for a week, i.e. Sunday 00:00:00 UTC
$currentInterval = mktime(0,0,0, date('m', $weekstart), date('d', $weekstart), date('Y', $weekstart));
return $currentInterval;
}
这里的 liveratetime 是一周中任意一天的纪元时间。基本上,此函数采用 liveratetime 并查找上周日,以便获取该特定 liveratetime 纪元的当前间隔。
但这里的问题是,每当我尝试从中获取特定 liveratetime 的当前间隔时
$createstart = strtotime('last Sunday', $getdate);
gives me
-345600
. And I am not getting why? can anyone please share a light on this.
这通常发生在过去的日期,例如
2007-10-02