strtotime() 第一个和最后一个的奇怪之处
$day = date('l', strtotime('07/25/2010'));
echo "$day ";
echo date("m/d/Y", strtotime("first $day"));
这会打印出Sunday 07/11/2010
$day = date('l', strtotime('07/25/2010'));
echo "$day ";
echo date("m/d/Y", strtotime("last $day"));
这会打印出Sunday 07/04/2010
这里发生了什么?不应该分别是 07/04/2010 和 07/25/2010 吗?
$day = date('l', strtotime('07/25/2010'));
echo "$day ";
echo date("m/d/Y", strtotime("first $day"));
This prints out Sunday 07/11/2010
$day = date('l', strtotime('07/25/2010'));
echo "$day ";
echo date("m/d/Y", strtotime("last $day"));
This prints out Sunday 07/04/2010
What's going on here? Shouldn't it be 07/04/2010 and 07/25/2010 respectively?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为答案是正确的,因为它们与给定日期相关(如果没有给出,则默认为今天)。
基于 PHP 文档:
所以第一个星期日实际上是 11 号,而最后星期日实际上是 4 号。根据您问题的措辞,您似乎正在寻找该月的第一个星期日和该月的最后一个星期日。此函数返回今天之后的第一个星期日和今天之前的最后一个星期日。
I think the answers are correct, because they are relative to the given date (which when not given defaults to today).
Based on the PHP docs:
So FIRST SUNDAY is in fact the 11th, and LAST SUNDAY was in fact the 4th. Based on the wording of your question, it appears you are looking for the 1st Sunday of the month, and the last Sunday of the month. This function returns the first Sunday AFTER today, and the LAST Sunday before today.
我可以对
last
说些什么,阅读 Datetime - 相对格式:我想它与
first
类似,它为您提供下一个dayname
。I can say something to
last
, read Datetime - Relative Formats:I guess it is similar with
first
it gives you the nextdayname
.