繁体   English   中英

PHP的Date_diff疯狂

[英]php date_diff craziness

有人可以向我解释这个“逻辑”吗?

$datetime1 = date_create('2012-04-01');
$datetime2 = date_create('2012-05-01');
$interval = date_diff($datetime1, $datetime2);
print_r($interval);

返回0m(月)和30d(天)。 但:

$datetime1 = date_create('2012-05-01');
$datetime2 = date_create('2012-06-01');
$interval = date_diff($datetime1, $datetime2);
print_r($interval);

返回1m(月)和1d(天)。

(PHP 5.3.15,LC_ALL en_US)

更新

我使用php_value date.timezone欧洲/阿姆斯特丹似乎有所作为。 仍然认为这很奇怪,是否是东部时间,应该只给1个月。 对?

http://sandbox.onlinephpfunctions.com/code/f28914a13f4047c79a19bae70570029a39196148

从PHP文档:

The DateInterval::format() method does not recalculate carry over points in
time strings nor in date segments. This is expected because it is not possible
to overflow values like"32 days" which could be interpreted as anything from
"1 month and 4 days" to "1 month and 1 day".

http://php.net/manual/en/dateinterval.format.php

尽管我确实感到奇怪,不同版本的PHP却不同的方式处理它

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM