2014-02-27 175 views
1

我有datetime对象:日期时间:: DIFF返回不正确的1小时差异

object(DateTime)[561] 
    public 'date' => string '1970-01-01 11:55:00' (length=19) 
    public 'timezone_type' => int 3 
    public 'timezone' => string 'Europe/Vilnius' (length=14) 

object(DateTime)[563] 
    public 'date' => string '2014-01-29 11:55:00' (length=19) 
    public 'timezone_type' => int 3 
    public 'timezone' => string 'Europe/Vilnius' (length=14) 

和令人惊讶的DateTime :: DIFF这些回报:

object(DateInterval)[565] 
    public 'y' => int 44 
    public 'm' => int 0 
    public 'd' => int 28 
    public 'h' => int 1 
    public 'i' => int 0 
    public 's' => int 0 
    public 'weekday' => int 0 
    public 'weekday_behavior' => int 0 
    public 'first_last_day_of' => int 0 
    public 'invert' => int 0 
    public 'days' => int 16099 
    public 'special_type' => int 0 
    public 'special_amount' => int 0 
    public 'have_weekday_relative' => int 0 
    public 'have_special_relative' => int 0 

任何想法,其中该1小时差异可能来自? 使用PHP 5.4.25 在此先感谢家伙!

+1

请发表您的代码,以便我们可以检查 –

+0

我已经发现了这个问题,同时挖掘更深的后使用Zend \ Form \ Element \ Date元素与Zend \ Validator \ DateStep进行问题。日期输入字段有一个选项,用于设置设置为** 1天**的日期输入的**最小**步骤。输入格式为Y-m-d,并且由JS日历选择,因此它自然有1天的步骤。但表单不验证,而DateStep验证程序在日期之间检测到1小时的更改,而最小步骤为1天。此外,使用PHP 5.3的WAMP似乎也可以正常工作。 – nesinervink

+1

无论如何,对于PHP 5.4+ [我无法复制](http://3v4l.org/mDiEU)那种情况。 –

回答

1

的比较时间当地,似乎出现了一个历史性的时区为Europe/Vilnius从UTC + 3H于1970年UTC + 2H变化在2014年:

$ export TZ="Europe/Vilnius" 
$ irb 
irb(main):001:0> Time.mktime(1970,1,1) 
=> Thu Jan 01 00:00:00 +0300 1970 
irb(main):002:0> Time.mktime(2014,1,1) 
=> Wed Jan 01 00:00:00 +0200 2014 

的变化似乎有时会出现回1990年

语言是红宝石,但它使用相同的操作系统后台对时间的功能和时区数据作为PHP

+0

谢谢!确实是这个原因。具体的+02:00时区是在01/01/2003引入的。 – nesinervink

0

这种差异不秀,在这里,用PHP 5.3.3 ...:

$ php -v 
PHP 5.3.3 (cli) (built: Dec 11 2013 03:29:57) 
Copyright (c) 1997-2010 The PHP Group 
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies 

<?php 
    date_default_timezone_set("Europe/Vilnius"); 
    $datetime1 = new DateTime('1970-01-01 11:55:00'); 
    $datetime2 = new DateTime('2014-01-29 11:55:00'); 
    $interval = $datetime1->diff($datetime2); 
    print_r($interval); 
?> 

DateInterval Object 
(
    [y] => 44 
    [m] => 0 
    [d] => 28 
    [h] => 0 
    [i] => 0 
    [s] => 0 
    [invert] => 0 
    [days] => 16099 
) 
+0

正如我在原帖的回复中提到的那样,它似乎也适用于使用PHP 5.3的WAMP机器。 – nesinervink

+0

对不起,我回答之前比你的评论... :-) – MarcoS

+0

然而,正如Alma Do显示(http://3v4l.org/mDiEU),它不会发生在最新的PHP ... – MarcoS