从以下格式的日期开始:2011-05-01 09:00:00
,如何创建一个包含一年中所有工作日(因此不包括所有周六和周日)的所有办公时间(09:00 到 17:00)的数组。我想要到达的是这样的:
2011-05-01 09:00:00
2011-05-01 10:00:00
2011-05-01 11:00:00
2011-05-01 12:00:00
2011-05-01 13:00:00
2011-05-01 14:00:00
2011-05-01 15:00:00
2011-05-01 16:00:00
2011-05-01 17:00:00
//next day, starting at 09:00 and ending at 17:00
2011-05-02 09:00:00
...
2011-05-02 17:00:00
//until the last day of the year from 09:00 to 17:00
2011-12-31 09:00:00
...
2011-12-31 17:00:00
开始日期将是当月的第一天,时间为 09:00,最后一个日期(数组的最后一个元素)将始终是一年中最后一天的 17:00。
同样,应排除周末。
伪代码想法:
我想到了类似strtotime($start, "+1 one hour")
检查的东西,"if smaller than 17:00"
但似乎没有那么简单。