title: How to convert a PHP DateTime object to ISO string?
body: <p>I have a date that I receive in MS format for JSON dates.  It looks like this:</p>
  
  <pre><code>/Date(1365004652303)/
  </code></pre>
  
  <p>I can convert it to a PHP DateTime object by doing this:</p>
  
  <pre><code>$timestamp = round(((int) $originalMSdate) / 1000);
  $convertedDate = new DateTime();
  $convertedDate-&gt;setTimestamp($timestamp);
  </code></pre>
  
  <p>Ultimately, though, I need it to be a string in ISO 8601 format.  I tried then converting it to an ISO date object &amp; then converting that to a string with strval() but strval() doesn't work on date objects.</p>
  
  <p>I've also tried </p>
  
  <pre><code>$dateString = date_format($convertedDate, 'YY-MM-DD H:i:s'); 
  </code></pre>
  
  <p>but I need it to also include timezone info, like this: 2015-10-01T21:22:57.057Z
  I don't see characters for that in date_format.  </p>
  
  <p>How can I achieve this?</p>
  
  <p>EDIT: I should clarify that I'm not printing the resulting string.  I need to pass it to a field in a database that accepts a string datatype.</p>