I'm having an issue that I cannot figure out.
I try to deal ALWAYS with UTC DateTime at server side.
I have an AspNetCore Mvc application with an endpoint that accepts queries that may include DateTimes. I want Mvc to understand that these dates are already in UTC and not to transform them "again".
My system is in Spain, (UTC +2)
If I send an http request to my localhost server like this:
http://localhost:50004/api/Resources?appliesOn=2018-06-30T18:00:00.000Z
I want to have the deserialized datetime as UTC representing the same date as:
DateTime.SpecifyKind(new DateTime(2018, 6, 30, 18, 0, 0), DateTimeKind.Utc)
But I can see that Mvc always transforms the date 2018-06-30T18:00:00.000Z into two hours later: 2018-06-30 20:00:00
I have tried to tell Mvc to use UTC json serializer/deserializer but nothing changes:
services
.AddMvc()
.AddJsonOptions(options =>
{
options.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Utc;
});
Is there a way to send query parameters in an http GET request already as a representation of UTC datetime? I understood a Date in ISO 8601, if it has a suffix Z it means "zero-offset" which should be interpreted already as UTC date time. Why Mvc is then transforming this and adding 2 hours offset?
Any clarification would be much appreciated!
PS: This is my endpoint, nothing special as you can see:
[HttpGet("")]
public IActionResult GetResources()
{
var displayUri = Request.GetDisplayUrl();
var requestUri = new Uri(displayUri);
var filter = _filteredRequestFactory.Create(requestUri);
var resources = _myProjection.GetResourcers(filter);
return Ok(resources);
}