问题描述
以下是问题的摘要:星期日, strtotime('本周')
返回下周的开始。
Here's a summary of the issue: On Sundays, strtotime('this week')
returns the start of next week.
在PHP中,这周似乎从星期一开始。但是,除了星期日以外的任何一天,这段代码
In PHP, the week seems to start on Monday. But, on any day except Sunday, this code
echo date('Y-m-d', strtotime('monday this week', strtotime('last sunday')));
输出本星期一的星期一,当星期一似乎应该输出星期一。在这种情况下,PHP似乎是在星期一和星期一当作本周的开始。现在是2012年12月10日星期一或2012-12-10。 date('Ym-d',strtotime('sunday last week'))
返回 2012-12-09
昨天。
Outputs the date of this week's Monday, when it seems like it should be outputting last weeks Monday. It seems like, in this case, PHP is treating both Sunday and Monday as the the start of the week. It's now Monday, Dec 10, 2012, or 2012-12-10. date('Y-m-d', strtotime('sunday last week'))
returns 2012-12-09
- yesterday.
这是一个错误,还是我错过了什么?这似乎是一个bug,这显然应该是相当知名的,但是我找不到任何东西。是星期天开始使用一些特殊处理方法吗?
Is this a bug, or am I missing something? It seems like a bug this obvious should be fairly well known, but I can't find anything about it. Is the only way to get the start of the week to use some special handling for Sundays?
$week_offset = (int) 'sunday' == date('l');
$week_start = strtotime("-$week_offset monday"); // 1 or 0 Mondays ago
推荐答案
就我而言可以说,这是一个bug。我看不出为什么 strtotime('this week');
应该返回未来的日期。这是一个很大的bug。在我特别的情况下,我有一个排行榜,从一周开始就向用户展示了最多的积分。但是在星期天,它是空的,因为 strtotime
为未来的日期返回时间戳。我很怀疑,因为我不知道这可能没有被忽视,但是我找不到任何关于这个错误的其他报告。
As far as I can tell, this is a bug. I see no logical reason why strtotime('this week');
should return a future date. This is a pretty major bug. In my particular case, I had a leaderboard that showed the users with the most points since the beginning of the week. But on Sundays, it was empty because strtotime
returned a timestamp for a future date. I was doubtful, because just I don't know how this could have gone unnoticed, but I couldn't find any other reports of this bug.
感谢你的所有时间和帮助,人们。
Thanks for all your time and help, folks.
这篇关于PHP:周从星期一开始,但是“星期一本周”星期天下周星期一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!