Our application heavilly relies on javascript (jQuery). So there are lots of 'application/json' requests.
We've been struggling with dates for some time, but despite our efforts we couldn't figure out how to deal with it in ASP.NET MVC application.
Here what we want:
- Serialize/deserialize DateTime objects on the server side (preferably with DateTimeKind.Utc).
- Work with Date object on the client side. Work with it in UTC. Format dates somehow.
Here are problems:
Date client object is always with end-user's timezone.
JSON.stringify(new Date())
automatically does a shift.JSON Stringify changes time of date because of UTC
This question helper a bit, but we need to remember to shift dates before sending it to the server. We also need to remember that we need a shift once we do
new Date('2012-10-19T10:23:47.778Z')
We know that JSON is not aware of dates, but it would be nice to have analogue of JSON.parse that would parse dates.We use Newton Json.net to serialize/deserialize dates, but it does it in DateTimeKind.Unspecified
Question:
Is there an elegant way to work with dates both on the server and client? We need it as a cross-cutting thing in the whole application.
UPD:
I had to put it more clearly. In our application we don't need take into account client time zones since we operate only with dates.
So if server returns 2012-10-19T10:23:47.778Z'
, we need Date object:
Fri Oct 19 2012 10:23:47 GMT+0300 (Kaliningrad Standard Time)
Not
Fri Oct 19 2012 13:23:47 GMT+0300 (Kaliningrad Standard Time)
(Date is shifted)