Passing DateTimeKind in ASP.NET Web Api 2.0 GET request
<p>I'm having trouble with DateTimes in my ASP.NET C# Web Api 2 project. I need to pass through an ISO 8601 date in my query string as follows:</p>

<pre><code>api/resource?at=2016-02-14T23:30:58Z
</code></pre>

<p>My controller method is as follows</p>

<pre><code>[HttpGet("/resource")]
public IActionResult GetResource([FromQuery]DateTime? at = null)
{
    if (!at.HasValue)
    {
        at = DateTime.UtcNow;
    }
    else
    {
        at = DateTime.SpecifyKind(at.Value, DateTimeKind.Utc);
    }

    // ...
}
</code></pre>

<p>Notice the little hack - the date is coming in with a DateTimeKind of Local, despite being specified with the 'Z' signifying UTC.  Dates should always be passed in UTC although I would ideally not like this to be a constraint.  I am using NodaTime internally and only expose DateTime in the query and response models for legacy reasons.  </p>

<ul>
<li><p>Why are my dates parsed to a DateTimeKind of local?</p></li>
<li><p>How can I read my UTC dates from query strings using ASP.NET web api 2?</p></li>
</ul>