【发布时间】:2018-08-28 11:36:44
【问题描述】:
我想获取接下来 18 个月的月份编号和年份。 我试过以下代码:
$dat=strtotime(date('Y-m-d'));
$mnth = date('n');
$yr=date('Y');
echo $mnth." | " . $yr . " | " . date("Y-m-d", $dat);
echo "<hr>";
for($i=0; $i<=18;$i++)
{
echo date("n", strtotime("+1 month", $dat)) ." | ".date("Y", strtotime("+1 month", $dat)) . " | " . date("Y-m-d", strtotime("+1 month", $dat)) ."<br><hr>";
$dat=date("Y-m-d", strtotime("+1 month", $dat));
}
迭代前的代码和第一次迭代的代码如下:
8 | 2018 | 2018-08-28
9 | 2018 | 2018-09-28
但所有后续迭代都给出以下错误:
注意:在 D:\Programs\PHP\aa\tdate.php 第 11 行
注意:在 D:\Programs\PHP\aa\tdate.php 第 11 行
注意:在 D:\Programs\PHP\aa\tdate.php 第 11 行 2 | 1970 | 1970-02-01
请提出一些解决方案。
【问题讨论】:
-
这是一种痛苦的方式来实现这一点
标签: php datetime datetime-format