title: PHP timezone function not working
body: <p>I'm creating a forum, which also stores the time a post was sent, and I need to convert that into the user's timezone.<br />
  Now, the MySQL DataBase stores the time with <code>UTC_TIMESTAMP()</code> (in a column with the <code>DATETIME</code> type), and I created a little function from the code on <a href="http://www.ultramegatech.com/blog/2009/04/working-with-time-zones-in-php/" rel="nofollow">http://www.ultramegatech.com/blog/2009/04/working-with-time-zones-in-php/</a> to convert the time to the user's timezone. This is the function:</p>
  
  <pre><code>function convertTZ($timestamp, $tz='UTC', $format='d-m-Y H:i:s') {
      // timestamp to convert
      $timestamp = strtotime($timestamp);
      // the time formatting to use
      $format = $format;
      // the time zone provided
      $tz = $tz;
  
      // create the DateTimeZone object for later
      $dtzone = new DateTimeZone($tz);
  
      // first convert the timestamp into an RFC 2822 formatted date
      $time = date('r', $timestamp);
  
      // now create the DateTime object for this time
      $dtime = new DateTime($time);
  
      // convert this to the user's timezone using the DateTimeZone object
      $dtime-&gt;setTimeZone($dtzone);
  
      // print the time using your preferred format
      $time = $dtime-&gt;format($format);
  
      return $time;
  }
  </code></pre>
  
  <p>And I made a test page at <a href="http://assets.momo40k.ch/timezones.php" rel="nofollow">http://assets.momo40k.ch/timezones.php</a>.<br />
  <br />
  Now, when I insert a post into the DataBase at, say, <code>11:50</code> in my timezone (which is <code>Europe/Rome</code>), it inserts <code>09:50</code> in UTC, wich is correct, according to some online timezone converters.<br />
  But when I try to convert it back to <code>Europe/Rome</code> with the <code>convertTZ()</code> function, it returns <code>09:50</code>, as if <code>Europe/Rome</code> is UTC. If I try converting it to a GMT+2:00 timezone, it returns <code>10:50</code>. Can anyone fugure out why this is?<br /><br /><br />
  P.S: I'm not using the <code>CONVERT_TZ()</code> <code>SQL</code> function because my server does not support named timezones, so this function is my workaround.</p>