我有一个PHP函数的问题。在某些情况下,我得到了错误的结果。例如:
$start = \Carbon\Carbon::create(2017, 4, 1);
$end = \Carbon\Carbon::create(2017, 5, 1);
echo $start->diffInMonths($end);我应该得到1,但我得到了0。我使用的是PHP7.1和Laravel 5.4。
有没有人有同样的问题?我怎么才能修复它?谢谢你的帮助!
发布于 2020-03-04 17:44:16
$start = \Carbon\Carbon::create(2017, 4, 1);
$end = \Carbon\Carbon::create(2017, 5, 1);
echo round($start->floatDiffInMonths($end));发布于 2017-05-10 06:42:48
正如github上的碳问题所说的那样,这是一个错误。这是more。
<?php
$d1 = new DateTime("2015-03-01 00:00:00.000000", new DateTimeZone('Europe/London'));
$d2 = new DateTime("2015-05-01 00:00:00.000000", new DateTimeZone('Europe/London'));
$diff = $d2->diff($d1);
print_r($diff);输出
DateInterval Object ( [y] => 0 [m] => 1 [d] => 30 [h] => 0 [i] => 0 [s] => 0 [f] => 0 [weekday] => 0 [weekday_behavior] => 0 [first_last_day_of] => 0 [invert] => 1 [days] => 61 [special_type] => 0 [special_amount] => 0 [have_weekday_relative] => 0 [have_special_relative] => 0 )https://stackoverflow.com/questions/43880879
复制相似问题