【发布时间】:2022-04-09 10:22:10
【问题描述】:
我是 php 新手。
我想问如何使每 x 减去或 x 小时递增循环日期并重复直到 x 次。
例子:
- 我有时间:2016-03-22T23:00:00
- 我想每 30 分钟增加一次时间
- 并重复直到 6 次。
输出将是:
- 2016-03-22T23:00:00
- 2016-03-22T23:30:00
- 2016-03-23T00:00:00
- 2016-03-23T00:30:00
- 2016-03-23T01:00:00
- 2016-03-23T01:30:00
我以前的代码在stackoverflow中形成了其他问题:
<?php
$startdate=strtotime("next Tuesday");
$enddate=strtotime("+1 weeks",$startdate); //16 weeks from the starting date
$currentdate=$startdate;
echo "<ol>";
while ($currentdate < $enddate): //loop through the dates
echo "<li>",date('Y-m-d', $currentdate),"T";
echo date('H:i:s', $currentdate);
echo "</li>";
$currentdate = strtotime("+30 minutes", $currentdate); //increment the current date
endwhile; // calculate date range
echo "<ol>";?>
在该代码上,循环停止直到所需日期。 我的问题是如何在需要的时间之前增加时间...,例如 5 、 10、 10、 500 次循环? 如何编码?
【问题讨论】: