strtotime()似乎被特殊日期窃听

gae*_*anm 0 php

我正在编写一个函数来计算两个日期之间的天数.

奇怪的是,我在一个特殊的日子里有一种奇怪的行为.这是我的代码的一部分:

$startTimestamp = strtotime('25-10-2014');
$endTimestamp   = strtotime('28-10-2014');

for($i = $startTimestamp; $i <= $endTimestamp; $i = $i + (60 * 60 * 24))
{
    echo date("d-m-Y", $i).'<br />';            
}
Run Code Online (Sandbox Code Playgroud)

这个例子给了我这个结果:

25-10-2014

26-10-2014

26-10-2014

27-10-2014

我不知道为什么日期"26-10-2014"出现两次.

如果我尝试其他日期,例如:

$startTimestamp = strtotime('25-11-2014');
$endTimestamp   = strtotime('28-11-2014');
Run Code Online (Sandbox Code Playgroud)

结果是正确的:

25-11-2014

26-11-2014

27-11-2014

28-11-2014

blu*_*112 7

这可能是因为PHP配置的时区中的DST(夏令时).

这意味着,如果你向前跳24小时,你仍然会在同一天,因为这一天是25小时.

  • 同意.最好让php通过使用strtotime("+ 1天)而不是60*60*24自动处理它 (3认同)