title: WebApi serialization for DateTime - how to deserialize?
body: <p>This code:</p>
  
  <pre><code>public class PhotoDescriptor
  {
      public DateTime DateCreatedUtc { get; set; }
  }
  
  public class PhotosController : ApiController
  {
      // GET api/photos
      public IEnumerable&lt;PhotoDescriptor&gt; GetListOfPhotos()
      {
          return new PhotoDescriptor[]
              {
                  new PhotoDescriptor
                      {
                          DateCreatedUtc = DateTime.ParseExact(
                                  "2012-07-24T00:28:41.8738770Z",
                                  "o",
                                  CultureInfo.InvariantCulture,
                                  DateTimeStyles.None).ToUniversalTime(),
                      },
                  new PhotoDescriptor
                      {
                          DateCreatedUtc = DateTime.ParseExact(
                                  "2012-07-24T00:28:41.0000000Z",
                                  "o",
                                  CultureInfo.InvariantCulture,
                                  DateTimeStyles.None).ToUniversalTime(),
                      },
              };
      }
  </code></pre>
  
  <p>returns the following JSON:</p>
  
  <pre><code>[{"DateCreatedUtc":"2012-07-24T00:28:41.873877Z"},
   {"DateCreatedUtc":"2012-07-24T00:28:41Z"}]
  </code></pre>
  
  <p><strong>notice that trailing zeros were removed from the datetime</strong>. But when I'm trying to parse these strings to get my DateTime back, I get <code>FormatException - String was not recognized as a valid DateTime</code>:</p>
  
  <pre><code>var date = DateTime.ParseExact("2012-07-24T00:28:41.873877Z", "o", CultureInfo.InvariantCulture, DateTimeStyles.None);
  </code></pre>
  
  <p>which is correct, according to MSDN <a href="http://msdn.microsoft.com/en-us/library/ms131038.aspx" rel="nofollow">DateTime.ParseExact Method</a>:</p>
  
  <blockquote>
    <p><em><strong>FormatException</em></strong> </p>
    
    <p>s does not contain a date and time that corresponds to
    the pattern specified in format.</p>
  </blockquote>
  
  <p>and <code>"o"</code> format <a href="http://msdn.microsoft.com/en-us/library/az4se3k1.aspx#Roundtrip" rel="nofollow">is defined</a> as follows:</p>
  
  <blockquote>
    <p>yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffffffK</p>
  </blockquote>
  
  <p>so clearly trailing zeros SHOULD be there.</p>
  
  <p>Is it a bug in WebApi, or am I doing something wrong? And how should I pass date/time field to my .Net client?</p>
  
  <p>Thank you.</p>