title: Converting time strings from local time to GMT in CakePHP
body: <p>How do you convert a DATETIME time string <em>from</em> a user's time zone <em>to</em> GMT in CakePHP?</p>
  
  <p>I'm aware of <code>CakeTime</code> and <code>TimeHelper</code>: They seem to handle converting time strings from server time to a user's local time very well, but they don't seem to cover dates that users submit. In one of my models, I've got a user-submitted time field that accepts input in DATETIME format, user's local time: <code>2014-04-07 04:48:05</code>. I need to convert this to UTC after the form is submitted.</p>
  
  <p>This is my controller method for my view. I'm trying to use CakeTime::format to convert the <code>sighted</code> field to UTC, but it moves the time the right number of hours in the wrong direction: Instead of converting 15:00EST to 19:00GMT, it converts it to 11:00 on save (!?).</p>
  
  <p>How do I convert it from local time to GMT using proper PHP time zones?</p>
  
  <pre><code>public function add() {
      App::uses('CakeTime', 'Utility');
      if ($this-&gt;request-&gt;is('post')) {
          $this-&gt;Post-&gt;create();
      // Change the submitted time to UTC before the post saves
          $this-&gt;request-&gt;data('Post.sighted', CakeTime::format($this-&gt;request-&gt;data['Post']['sighted'], '%Y-%m-%d %H:%M:%S', 'UTC'));
          if ($this-&gt;Post-&gt;save($this-&gt;request-&gt;data)) {
              $this-&gt;redirect(array('action' =&gt; 'view', $this-&gt;Post-&gt;id));
          } else {
              $this-&gt;Session-&gt;setFlash(__('The post could not be saved. Please, try again.'), 'flash/error');
          }
      }
      // Get local time and set the field before the view loads
      $this-&gt;request-&gt;data['Post']['sighted'] = CakeTime::format(date('Y-m-d H:i:s'), '%Y-%m-%d %H:%M:%S', 'N/A', 'America/New_York');
  }
  </code></pre>