title: How do I convert dates returned from webapi in string format to javascript date format for AngularJs
body: <p>I have a number of .net webApi actions returning dates that are deserialised into JSON. My angular application then consumes these date strings for display\edit or as the ngModel in a variety of date directives. Many of these directives require a javascript date object and not a string representation of a date. How do serialise the date string back to javascript date for all returned webapi data?</p>
  
  <p>N.B. I have tried a variety of regExs that proport to be ISO 8601 compliant, but for every one I use there are a bunch of use cases that fail. The cases I require are as follows:</p>
  
  <ol>
  <li>should not convert non dates (string) e.g. '<a href="http://blah/" rel="nofollow">http://blah/</a>' </li>
  <li>should not convert non dates (integer) e.g. 2015</li>
  <li>should not convert bad dates e.g. '2009-05-19T14a39r'</li>
  <li>should not convert partial bad date from string to date e.g. '1'</li>
  <li>should not convert a string that looks like a year e.g. '2015'</li>
  <li>should convert date from string to date e.g. '2015-09-09'</li>
  <li>should convert date with time from string to date with time e.g. '2009-05-19T14:39'</li>
  <li><p>should convert date with time from string to date with time including seconds e.g. '2009-05-19T14:39:23'</p></li>
  <li><p>should convert date with time to the millisecond from string to date with time with milliseconds e.g. '2016-06-09T13:02:39.957'</p></li>
  <li><p>should convert date with time from string to date with time in UTC e.g. '2009-05-19T14:39Z'</p></li>
  <li><p>should not convert a date which is part of a longer string e.g. 'Should not convert 2015-12-12T00:00:00Z as this is part of a longer string'</p></li>
  </ol>