title: Google Calendar API date time
body: <p>I'm trying to get the Google Calendar Api to work. Without the use of my $_POST date times it works perfect. But then the date is hard coded like the google ones and that is not what i want. When i use my $_POST vars it shows me this error:</p>
  
  <pre><code>Fatal error: Uncaught exception 'Google_Service_Exception' with message 'Error calling POST https://www.googleapis.com/calendar/v3/calendars/%40group.calendar.google.com/events?key=: (400) **Start and end times must either both be date or both be dateTime**.'
  </code></pre>
  
  <p>My dateTime code:</p>
  
  <pre><code>  if ($client-&gt;getAccessToken()){
    $dt = new DateTime();
    echo $dt-&gt;format("Y-m-d\TH:i:s.000+01:00") . "\n";
  
    if (isset($_POST['addevent'])){
    echo "&lt;hr&gt;&lt;font size=+1&gt;I have access to your calendar&lt;/font&gt;";
    $event = new Google_Service_Calendar_Event();
    $event-&gt;setSummary($_POST['title']);
    $event-&gt;setLocation($_POST['location']);
    $start = new Google_Service_Calendar_EventDateTime();
    $start-&gt;setTimeZone('Europe/Amsterdam');
    $start-&gt;setDateTime($dt);
    $event-&gt;setStart($start);
    $end = new Google_Service_Calendar_EventDateTime();
    $end-&gt;setDateTime($dt);
    $event-&gt;setEnd($end);
    $createdEvent = $cal-&gt;events-&gt;insert('f8ov32gchvan0b6a0594r72jng@group.calendar.google.com', $event);
    echo "&lt;br&gt;&lt;font size=+1&gt;Event created&lt;/font&gt;";
  
    echo "&lt;hr&gt;&lt;br&gt;&lt;font size=+1&gt;Already connected&lt;/font&gt; (No need to login)";
  
    }
  </code></pre>
  
  <p>I'm also experimenting with   <code>echo $dt-&gt;format("c") . "\n";</code>
  which is giving me the same thing only without .000 .
  Google Calendar requires me to have a dime time format like:</p>
  
  <pre><code>$start-&gt;setDateTime('2012-10-31T10:00:00.000-05:00');
  $event-&gt;setStart($start);
  $end = new Google_EventDateTime();
  $end-&gt;setDateTime('2012-10-31T10:25:00.000-05:00');
  $event-&gt;setEnd($end);
  </code></pre>
  
  <p>Source: <a href="https://stackoverflow.com/questions/18690653/create-simple-google-calendar-event-in-php">Create Simple Google Calendar Event in PHP</a></p>
  
  <p>My HTML input fields:</p>
  
  <pre><code>&lt;input type="datetime-local" name="date1"&gt;Date1&lt;br&gt;
  &lt;input type="datetime-local" name="date2"&gt;Date2&lt;br&gt;
  </code></pre>
  
  <p>ATM i'm not using my $_POST i'm checking with </p>
  
  <pre><code>$dt = new DateTime();
  echo $dt-&gt;format("Y-m-d\TH:i:s.000+01:00") . "\n";
  </code></pre>
  
  <p>So my question is, How do i get the google time format with PHP?</p>
  
  <p>Thank you</p>