加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

PHP Carbon diffInMonths

发布时间:2020-12-13 22:27:53 所属栏目:PHP教程 来源:网络整理
导读:我有 PHP Carbon diffInMonths函数的问题. 在某些情况下,我得到错误的结果. 例如: $start = CarbonCarbon::create(2017,4,1);$end = CarbonCarbon::create(2017,5,1);echo $start-diffInMonths($end); 我应该得到1,但我得到0. 我使用PHP 7.1和Laravel 5
我有 PHP Carbon diffInMonths函数的问题.
在某些情况下,我得到错误的结果.
例如:

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

echo $start->diffInMonths($end);

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

有没有人有同样的问题?我该如何解决?
谢谢您的帮助!

解决方法

由于 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 )

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读