jjzjj

PHP Carbon diffInMonths

coder 2024-04-19 原文

我对 PHP Carbon diffInMonths 函数有疑问。 在某些情况下,我得到了错误的结果。 例如:

$start = \Carbon\Carbon::create(2017, 4, 1);
$end   = \Carbon\Carbon::create(2017, 5, 1);

echo $start->diffInMonths($end);

我应该得到 1,但我得到了 0。 我使用 PHP 7.1 和 Laravel 5.4。

有人遇到同样的问题吗?我该如何解决? 感谢您的帮助!

最佳答案

$start = \Carbon\Carbon::create(2017, 4, 1);
$end   = \Carbon\Carbon::create(2017, 5, 1);

echo round($start->floatDiffInMonths($end));

关于PHP Carbon diffInMonths,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43880879/

有关PHP Carbon diffInMonths的更多相关文章

随机推荐