C.J. C.J. - 1 month ago 6
Javascript Question

How to make ASP.Net MVC model binder treat incoming date as UTC?

I'm posting an object to an MVC controller. The object contains a field called StartDt and on the client it is a javascript Date object in local time.

When I call JSON.stringify on the object and POST it to the server using jQuery's ajax method I can see in Firebug that what's being sent to the server is an ISO string like "1900-12-31T13:00:00.000Z" which I believe should be the local time in UTC format.

When I look at the DateTime field in my controller though, it looks like its back to local time and not UTC. How can I fix this?

I want to store the UTC version of the Date that came from the client.

Answer Source

You may have to use the DateTime.ToUniversalTime() method to get back the UTC time.