看看这段代码:
$first = DateTime::createFromFormat('Y-m', '2001-07');
$last = DateTime::createFromFormat('Y-m', '1998-06');
$interval = $first->diff($last);
echo "m diff: ".$interval->m." y diff: ".$interval->y."\n";
输出是m diff: 0 y diff: 3
为什么它返回错误的月差?
有趣的是,如果我将日期更改为“2001-08”和“1998-07”,它会返回正确的月份间隔 ==1。
谢谢!