title: How to have WebApi querystring parameter binding keep UTC dates?
body: <p>I am sending in my querystring a UTC date, e.g.</p>
  
  <blockquote>
    <p>&amp;EndDate=2000-01-02T03%3a04%3a05.0060000Z</p>
  </blockquote>
  
  <p>And my controller parameter binds it in a complex object, e.g.</p>
  
  <pre><code>    public async Task&lt;DocumentsRequest&gt; GetEchoFromUriDocumentsAsync(
                                              [FromUri] DocumentsRequest request)
      {
          return request; 
      }
  </code></pre>
  
  <p>What I've managed to figure out is that my object after parameter binding, changes my UTC date to a local date + offset. Here is a snippet of my test case</p>
  
  <pre><code>    [TestMethod]
      public void Should_generate_querystring_and_parameter_bind_correctly()
      {
  
          DocumentsRequest request = DocumentRequestBuilder.DocumentsRequest();
          string queryString = ReflectionQueryStringConverter.ToQueryString(request);
  
          string baseUrl = "http://baseUrl/Test/EchoFromUriDocuments";
          string uri = baseUrl + queryString;
          HttpResponseMessage response = _client.GetAsync(uri).Result;
          string outputString = response.Content.ReadAsStringAsync().Result;
  
          JsonSerializer&lt;DocumentsRequest&gt; serializer = 
              new JsonSerializer&lt;DocumentsRequest&gt;();
          DocumentsRequest output = serializer.DeserializeFromString(outputString);
  
          output.EndDate.Should().Be(request.EndDate);
   }
  </code></pre>
  
  <p>The above is failing because the output is:</p>
  
  <blockquote>
    <p>2000-01-01T19:04:05.006-08:00</p>
  </blockquote>
  
  <p>But, the json serialization then truncates the offset and assumes it is UTC date... and as you can see, the dates don't match up post-round-trip.</p>
  
  <p>There is a similar question here, but not really an answer (the poster answered is own question)</p>
  
  <p><a href="https://stackoverflow.com/questions/22581138/passing-utc-datetime-to-web-api-httpget-method-results-in-local-time">Passing UTC DateTime to Web API HttpGet Method results in local time</a></p>
  
  <p>What is the correct solution to resolve this issue? I think the issue is that I  want the parameter binding to parse the querystring as UTC a date. Is TypeConverter the way to go? Anyone have a complete sample of how to do that? Would I have to use the TypeConverter on all attribute on all my classes with DateTime? I was hoping for a global configuration of sorts.</p>
  
  <p>Thanks.</p>