Php 返回STROTIME之间的所有天”;现在";及+;“2周”;
如何返回两个strotime函数之间的所有天数?我肯定我需要一个foreach循环,但不知道如何进行Php 返回STROTIME之间的所有天”;现在";及+;“2周”;,php,date,strtotime,Php,Date,Strtotime,如何返回两个strotime函数之间的所有天数?我肯定我需要一个foreach循环,但不知道如何进行 echo date("jS F, Y", strtotime("now")); echo "<br />"; echo date("jS F, Y", strtotime("+2 weeks")); echo日期(“jsf,Y”,strottime(“now”); 回声“”; 回音日期(“jS F,Y”,标准时间(“+2周”); 基
echo date("jS F, Y", strtotime("now"));
echo "<br />";
echo date("jS F, Y", strtotime("+2 weeks"));
echo日期(“jsf,Y”,strottime(“now”);
回声“
”;
回音日期(“jS F,Y”,标准时间(“+2周”);
基本思想
<?php
for ($i = 1; $i <= 14; $i++) {
echo date("jS F, Y", strtotime("now + $i day"));
echo "<br />";
}
?>
使用迭代器类。文档中的示例:
$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" );
}
for循环的计数每天递增14,由
strotime
返回的unix时间戳为秒。一天有86400秒。这是循环增量的。在循环中进行日期转换。“一天有86400秒。”不总是这样做的`$begin=new DateTime(“现在”)$结束=新日期时间(“+2周”)$interval=DateInterval::createFromDateString('1天')$period=新日期period($begin,$interval,$end);foreach($dt){echo$dt->format(“ly-m-dh:i:s\n”)}`谢谢您的帮助!