PHP Carbon diffInMonths
作者:互联网
我有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.
有没有人有同样的问题?我该如何解决?
谢谢您的帮助!
解决方法:
<?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 )
标签:php,datetime,php-carbon 来源: https://codeday.me/bug/20190710/1427888.html