4

I've got some code similar to:

 [HttpGet("SearchStuff")]
    public IActionResult SearchStuff([FromQuery]DateTime from, [FromQuery]DateTime to)

I want to make sure I receive in UTC as follows: If a timezone is specified then convert to UTC If no timezone is specified then assume UTC and specify as UTC

I tried sending as utc from the client like this (Client works in local time), and it formats as I would expect but unfortunately serverside the datetime was converted to local time of the server. If I use ToString("s") the server receives the correct datetime value but unfortunately with DatetimeKind.Unspecified:

protected string Format(DateTime t)
{
    return t.ToUniversalTime().ToString("o");
}
Jesper
  • 331
  • 3
  • 12

1 Answers1

1

There is also this https://github.com/dotnet/aspnetcore/issues/11584 which provides a workaround it

herme 0
  • 912
  • 1
  • 9
  • 23