【发布时间】:2011-10-22 23:06:05
【问题描述】:
首先,我要做的是获取特定日期后接下来 7 天的日期。对于第一组,我希望我的结果是 11/1/11 到 11/7/11。这是代码,以及它给我的结果。这非常非常奇怪。
$date = "October 31, 2011";
$nxtMon = strtotime(date("Y-m-d", strtotime($date)) . "monday");
$nxtTue = strtotime(date("Y-m-d", strtotime($date)) . "tuesday");
$nxtWed = strtotime(date("Y-m-d", strtotime($date)) . "wednesday");
$nxtThu = strtotime(date("Y-m-d", strtotime($date)) . "thursday");
$nxtFri = strtotime(date("Y-m-d", strtotime($date)) . "friday");
$nxtSat = strtotime(date("Y-m-d", strtotime($date)) . "saturday");
$nxtSun = strtotime(date("Y-m-d", strtotime($date)) . "sunday");
它给了我:
2011-10-31 <--- I Want the Next Monday
2011-11-01
2011-11-02
1969-12-31 <--- ???????
2011-11-04
2011-11-05
2011-11-06
然后我把它改成这样:
$date = "October 31, 2011";
$nxtMon = strtotime(date("Y-m-d", strtotime($date)) . "next monday");
$nxtTue = strtotime(date("Y-m-d", strtotime($date)) . "next tuesday");
$nxtWed = strtotime(date("Y-m-d", strtotime($date)) . "next wednesday");
$nxtThu = strtotime(date("Y-m-d", strtotime($date)) . "next thursday");
$nxtFri = strtotime(date("Y-m-d", strtotime($date)) . "next friday");
$nxtSat = strtotime(date("Y-m-d", strtotime($date)) . "next saturday");
$nxtSun = strtotime(date("Y-m-d", strtotime($date)) . "next sunday");
它给了我:
2011-11-07 <--- Wow, it works!
2011-11-01 <--- Wow, it works!
2011-11-02 <--- Wow, it works!
2011-11-03 <--- Wow, it works!
2011-11-04 <--- Wow, it works!
2011-11-05 <--- Wow, it works!
2011-11-06 <--- Wow, it works!
现在我尝试使用与今天相同的日期:
$date = "October 22, 2011";
$nxtMon = strtotime(date("Y-m-d", strtotime($date)) . "next monday");
$nxtTue = strtotime(date("Y-m-d", strtotime($date)) . "next tuesday");
$nxtWed = strtotime(date("Y-m-d", strtotime($date)) . "next wednesday");
$nxtThu = strtotime(date("Y-m-d", strtotime($date)) . "next thursday");
$nxtFri = strtotime(date("Y-m-d", strtotime($date)) . "next friday");
$nxtSat = strtotime(date("Y-m-d", strtotime($date)) . "next saturday");
$nxtSun = strtotime(date("Y-m-d", strtotime($date)) . "next sunday");
我明白了:
2011-10-24
2011-10-25
2011-10-26
2011-10-27
2011-10-28
2011-10-29
2011-10-23 Hooray, it still works!
我似乎已经弄清楚了如何得到我想要的东西,但事实是,在我输入这个问题之前,它似乎并没有正常工作。现在突然就这样了。在不改变任何东西的情况下,它似乎有时有效,有时无效。由于第一个结果中 1969 年的怪异,我感觉我不知道发生了什么。
这看起来像我想做的事情的好方法吗?
如果有人知道输入日期并获取接下来 7 个日期的更好方法,您能帮帮我吗?或者告诉我 1969 年是关于什么的?直到昨天,当我注意到星期四的结果没有出现在我的页面上时,一切似乎都运行良好,我追查到了这一点。感谢您的宝贵时间。
【问题讨论】: