如何返回两个 strtotime 函数之间的所有天数?我确信我需要一个 foreach 循环,但不知道如何去做。
echo date("jS F, Y", strtotime("now"));
echo "<br />";
echo date("jS F, Y", strtotime("+2 weeks"));
使用DatePeriod迭代器类。文档中的示例:
$begin = new DateTime( '2007-12-31' );
$end = new DateTime( '2009-12-31 23:59:59' );
$interval = DateInterval::createFromDateString('last thursday of next month');
$period = new DatePeriod($begin, $interval, $end, DatePeriod::EXCLUDE_START_DATE);
foreach ( $period as $dt ) {
echo $dt->format( "l Y-m-d H:i:s\n" );
}
基本思想..
<?php
for ($i = 1; $i <= 14; $i++) {
echo date("jS F, Y", strtotime("now + $i day"));
echo "<br />";
}
?>