有人能解释一下这个'逻辑'吗?
$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
答案 0 :(得分:0)
来自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确实处理它 不同