5

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");
}
1

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.