如何从 PHP 中的两个日期范围中提取每周一和每两周的周一?
我正在使用臭名昭著的 jQuery UI 的日期选择器,并在我的表单中选择两个日期的范围。
第一个代表开始日期,另一个代表结束日期。
我现在需要的是计算这两个日期之间每周一的算法、一些提示和方向或帮助者。
例如:
start: 2011-06-01
end: 2011-06-30
应该为我提取周一的这四(四)个日期:
1st: 2011-06-06
2nd: 2011-06-13
3rd: 2011-06-20
4th: 2011-06-27
我怎样才能实现这一点?
而且,我每两周星期一都需要它:
每两周的结果应该是:
1st: 2011-06-06
2rd: 2011-06-20
I'm using the infamous jQuery UI's Datepicker, and in my form I select a range of two dates.
First represents the starting date and the other represents the end date.
What I need now is the algorthm, some tips and directions or helpers for calculating every Monday between these two dates.
For instance:
start: 2011-06-01
end: 2011-06-30
Should extract me these 4 (four) dates witch lay on Mondays:
1st: 2011-06-06
2nd: 2011-06-13
3rd: 2011-06-20
4th: 2011-06-27
How could I achive this?
And also, I'd need it for every fortnightly Monday:
Result for fortnightly should be:
1st: 2011-06-06
2rd: 2011-06-20
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
现在您的所有星期一都在
$mondays
数组中。附录
请注意,由于夏令时,
+86400
可能会导致结果不一致。如果您的应用是关键任务,最好使用+1 天
strtotime('2010-10-31') + 86400
返回2010-10-31
>Now you have all your mondays in
$mondays
array.Addendum
Be aware that
+86400
could lead to inconsistent result due to daylight saving. If your app is mission-critical better use+1 day
strtotime('2010-10-31') + 86400
returns2010-10-31
}
}