title: AngularJS convert Date to getTime() before sending to server
body: <p>I have a form that uses <code>&lt;input type="datetime-local" ng-bind="course.endDate"..</code> and sets a variable of the model.
  Before sending the date to the server I've to convert the date <code>2015-04-04T22:00:00.000Z</code> to a <code>integer</code> given by the <code>getTime()</code>.</p>
  
  <p>In the controller i added this: <code>course.endDate = course.endDate.getTime();</code> it works for the server side but angular complains in the console with <a href="https://docs.angularjs.org/error/ngModel/datefmt?p0=1325458800000" rel="nofollow">this error</a>.  (<em>as said, it works, but I would like to avoid errors</em>)</p>
  
  <pre><code>Error: [ngModel:datefmt] Expected `1325458800000` to be a date
  http://errors.angularjs.org/1.3.15/ngModel/datefmt?p0=1325458800000
      at REGEX_STRING_REGEXP (angular.js:63)
      at Array.&lt;anonymous&gt; (angular.js:19938)
      at Object.ngModelWatch (angular.js:23419)
      at Scope.$get.Scope.$digest (angular.js:14300)
      at Scope.$get.Scope.$apply (angular.js:14571)
      at done (angular.js:9698)
      at completeRequest (angular.js:9888)
      at XMLHttpRequest.requestLoaded (angular.js:9829)
  </code></pre>
  
  <p>How can i do then? </p>
  
  <p>I had the idea of adding some fields that are used in the form (<code>formEndDate</code>) and convert to another one (<code>endDate = formEndDate.getTime()</code>) for the server side, but in this way the server refuse the call since the parameter <code>formEndDate</code> is not allowed, and if I remove the <code>formEndDate</code> then everything breaks.</p>
  
  <p><strong>additional problem:</strong>
  When i fetch data from the server I have an integer that needs to be converted into a date to be used in the form. so I've to convert the date also before allowing an edit. how can I do this? (the data fetched are into an array, so would be terrific to have the conversion without having to iterate on the whole array)</p>
  
  <h2>solution</h2>
  
  <p>thanks to the two answers (I set correct the first that came) I also (somehow) solved the problem of the form when editing. I did so by creating an extra field and use it for the form when editing (I do inline editing).</p>
  
  <p>I created a gist <a href="https://gist.github.com/esseti/fcb3d5257ef6df812f01" rel="nofollow">here</a> </p>