title: ASP.NET DateTime Serialization in QueryString vs Body
body: <p>I noticed <code>DateTime</code> objects are serialized differently for the same values between QueryString and Body. The underlying value is still the same correct value, however the serialized QueryString has a <code>DateTimeKind</code> of <code>Local</code>, whereas the Body is <code>Utc</code>.</p>
  
  <h3>Endpoint</h3>
  
  <pre class="lang-cs prettyprint-override"><code>[HttpPost]
  public ActionResult Post([FromQuery] DateTime queryDate, [FromBody] DateTime bodyDate)
  {
    var result = new
    {
      queryDateKind = queryDate.Kind.ToString(),
      bodyDateKind = bodyDate.Kind.ToString()
    };
  
    return new ObjectResult(result);
  }
  </code></pre>
  
  <h3>Request</h3>
  
  <pre><code>POST /api/values?queryDate=2019-05-12T00%3A00%3A00.000Z HTTP/1.1
  Host: localhost:5000
  Content-Type: application/json
  cache-control: no-cache
  "2019-05-12T00:00:00.000Z"
  </code></pre>
  
  <h3>Response</h3>
  
  <pre><code>{
      "queryDateKind": "Local",
      "bodyDateKind": "Utc"
  }
  </code></pre>
  
  <p>Any idea why this is? Is there perhaps a setting to always serialize to the same <code>DateTimeKind</code>?</p>
  
  <p>Preferably I wouldn't want to use <code>ToUniversalTime()</code> or <code>ToLocalTime()</code> everywhere, nor use any custom <code>IModelBinder</code>.</p>