How can I prevent converting ASP.NET MVC from UTC to local?

I store dates in a database using UTC. The client (javascript) receives the date and converts it to local time. This works great when working on localhost (which means that the time zone of the web server is the same as the time zone of the client). However, when I deploy Azure, where the web server’s time zone is UTC, I return the date already set to the client’s time zone, forcing the client to display the wrong time value.

I assume ASP.NET MVC is doing this conversion. It's true? If so, how can I prevent this and make the dates be passed unchanged?

I tried to set the type of the datetime passed object to DateTimeKind.UnSpecified, but this does not work.

+4
source share
1 answer

If you save the value in UTC and send it as UTC, the web server clock does not come into play. You need to check how this date gets the set from db, if that is good, and then check that the conversion is happening in JavaScript.

In addition, if you use any .ToString () or use HtmlHelpers, they can also convert on the fly.

+1
source

All Articles