DateTime :: diff () не зависит от часового пояса, но всегда возвращает одно и то же значение

Я добавляю данные аукциона в свою систему. Например:

user's timezone  is : `America/Denver`
auction start time is : Thu, 21 Jun 2012 03:46:22 AM
auction period : 1 day.
auction end time : Fri, 22 Jun 2012 03:46:22 AM

Я храню всю эту информацию, как она есть в моей БД (т.е.all stored time based on user's timezone).

Теперь я хочу актуальныйdifference between end time and current time (из Америки / часовой пояс Денвера).

я использовалDateTime() функции

so even I don't convert the timezone; it returns same difference (and that is wrong too).

Мой код PHP ниже; Вы также можете найти его наCodePad

$end_time = 'Fri, 22 Jun 2012 03:46:22 AM';
$tz = 'America/Denver';
dateDifference($end_time,$tz);

function dateDifference($end, $tz = NULL)
    {
      $owner_tz = new DateTimeZone($tz);
      //var_dump($owner_tz->getName()); 

      $from  = new DateTime("now", new DateTimeZone('GMT'));     
      $from ->setTimeZone($owner_tz);

      $to = new DateTime($end,new DateTimeZone('GMT'));
      /* @Note:I have commented below setTimeZone() because I have already stored 
       * `end time` as per user's  timezone, So I dont need to convert it again 
       * into user's timezone.you can un-comment below line. 
       * it doesn't affect the results anyways.
       */
     //$to ->setTimeZone($owner_tz);        

    //procedural style using date_diff()
    $interval = date_diff($from, $to);        
    var_dump($interval); 

    // OO style using dateTime::diff()
    $interval = $from->diff($to);       
    var_dump($interval);     
}

Возвращает:

object(DateInterval)[4]
  public 'y' => int 0
  public 'm' => int 0
  public 'd' => int 0
  public 'h' => int 16
  public 'i' => int 40
  public 's' => int 24
  public 'invert' => int 0
  public 'days' => int 6015

References:

DateTime() DateTime::diff DateTime::setTimeZone Handling timezone conversion with PHP DateTime

Ответы на вопрос(2)

Ваш ответ на вопрос