How to get the date of every monday in a month for a given year

て烟熏妆下的殇ゞ 提交于 2019-12-02 06:35:57

问题


I'm trying to get the date of every Monday in a month. I previously did this for every first Monday and it worked.

$date = strtotime("second monday of $month[$i] $year[j]");

But this didn't work for every monday

$date = strtotime("every monday of $month [$i] $year[j]");

I'm getting the month and year from an array.


回答1:


Why don't you get first monday, and do a loop adding 7 days to it until it is next year?

$first = strtotime("first monday of $year[$j]");
$lastday = mktime(0, 0, 0, 12, 31, $year[$j]);

$day = $first;
do {
    echo date('M d, Y', $day);
    $day += 7 * 86400;

} while ($day < $lastday);


来源:https://stackoverflow.com/questions/12554697/how-to-get-the-date-of-every-monday-in-a-month-for-a-given-year

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!