本文介绍了如何在一个月内每个星期一的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正尝试在一个月内获得每个星期一的日期。我以前每个第一个星期一都这样做,它的工作。
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.
推荐答案
为什么你没有得到第一个星期一,并循环添加7天,直到明年?
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);
这篇关于如何在一个月内每个星期一的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!