title: Handle datetime between php (Laravel API) and javascript (AngularJS)
body: <p>I'm trying to make my Laravel API exchange dates with my Angularjs frontend.</p>
  
  <p>It works from Laravel to JS by first converting my mysql datetime initial value:</p>
  
  <pre><code>2015-08-19 10:00:00
  </code></pre>
  
  <p>using <code>$newdate = Carbon::parse($event['date'])-&gt;toATOMString();</code> which outputs:      </p>
  
  <pre><code>2015-08-19T10:00:00+00:00
  </code></pre>
  
  <p>, then converting it later to a javascript date object (Angularjs) using <code>event.date = new Date(event.date);</code> which outputs:</p>
  
  <pre><code>Date 2015-08-19T10:00:00.000Z
  </code></pre>
  
  <p><strong>Problem</strong>: <strong>posting my updated Javascript date object back to my PHP API</strong> to update the value in mysql db (datetime). Carbon doesn’t like the date format he gets back:</p>
  
  <pre><code>2015-08-19T11:00:00.000Z
  </code></pre>
  
  <p>And I’m not sure how to handle this. I get the following error from my Laravel log: <code>exception 'InvalidArgumentException' with message 'Trailing data' … Carbon/Carbon.php:392</code></p>
  
  <p><strong>Question</strong>: How should I convert the above formatted date in php so Carbon accepts it? </p>
  
  <p>I don't need to record seconds, so my Laravel model handles dates like so:</p>
  
  <pre><code> $this-&gt;attributes['date'] = Carbon::createFromFormat('Y-m-d H:i', $date);
  </code></pre>
  
  <p>Here's what I tried (with no success) up until now. I'm obviously missing something and not sure what i'm doing.</p>
  
  <pre><code>/**
   * Store updates to event.
   *
   * @return Response
   */
  public function update($id)
  {   
      $event = Event::findOrFail($id);
  
      $date  = Request::get('jsdateobject');
  
      // ------------------------------------------------------------     
      // trying to handle following format: 2015-08-19T11:00:00.000Z
      // ------------------------------------------------------------
  
      // $date = Carbon::parse($date)-&gt;toATOMString();        // didn't work - outputs: 2015-08-19T11:00:00+00:00
      // $date = Carbon::parse($date)-&gt;toDateTimeString();    // didn't work - outputs: 2015-08-19 11:00:00
      // $date = Carbon::parse($date)-&gt;toW3cString();         // didn't work - outputs: 2015-08-19T11:00:00+00:00
      // $date = new Carbon($date);                           // didn't work - outputs: 2015-08-19 11:00:00
      $date = Carbon::createFromFormat('Y-m-d\TH:i:s.uO', $date); // didn't work - outputs: 2015-08-19 11:00:00
  
      $event-&gt;date = $date;
      $event-&gt;update();
  
      return Response::json(array('success'=&gt;true));
  }       
  </code></pre>