0

誰かが私にこの「論理」を説明できますか?

$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 Europe/Amsterdam を使用していますが、これが違いを生むようです。それでも、東部時間であろうとなかろうと、それは奇妙だと思いますが、1か月しか与えられないはずです. 右?

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

4

1 に答える 1

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の異なるバージョンがそれを異なる方法で処理するのは奇妙だと思いますが

于 2012-12-04T21:26:21.737 に答える