我可以在接下来的4周内填写每个星期一的日期。问题是当星期一上午12点到达时,会立即将日期提前一周。我不希望它在周一结束之前这样做,就像周二早上12点那样。有什么想法吗?
$start = strtotime( "next monday" );
$end = strtotime( "+4 weeks", $start );
while ( $start < $end ) {
$dates[] = date( "D, M d", $start );
$start = strtotime( "+1 week", $start );
}
也许我可以离开阵列,只是在回声时改变它?这就是我现在正在做的事情。
<h3><?php echo $dates[0]; ?></h3>
<p></p>
<h3><?php echo $dates[1]; ?></h3>
<p></p>
等等
答案 0 :(得分:1)
答案 1 :(得分:0)
从今天开始的第一天
$start = strtotime( "-1 day" );
$start = strtotime( "next monday", $start );
答案 2 :(得分:0)
正如您所指出的那样,问题是strtotime("next monday")
在星期日返回本周的星期一,而在星期日之后下周一。
似乎你总是想要本周的星期一。因此,您可以使用本周的相对时间字符串星期一:
$start = strtotime('monday this week');
答案 3 :(得分:0)
我明白了。我刚才添加了一个if语句。如果当天是星期一,它只会将开始日期一周移动到&#34;过去&#34;使它等于今天的日期。这就是整个事情:
$start == strtotime( 'next monday' );
if( date('N') == 1 ) {
$start = strtotime( '-1 week', $start );
}
$end = strtotime( '+4 weeks', $start );
while ( $start < $end ) {
$dates[] = date( 'D, M d', $start );
$start = strtotime( '+1 week', $start );
}